fix: redirect remaining auth throws that crash prerendering
getUserIdAndUsername() and getAccountContext() also threw generic errors when no session exists. Same fix as apikeys: use redirect() which Next.js handles as a prerender bailout signal.
This commit is contained in:
parent
09ed4d4b44
commit
71127055f3
2 changed files with 3 additions and 2 deletions
|
|
@ -18,7 +18,7 @@ export async function getUserIdAndUsername(): Promise<{ username: string; userId
|
||||||
const session = await getCachedSession()
|
const session = await getCachedSession()
|
||||||
|
|
||||||
if (!session?.user?.sub || !session?.user?.nickname) {
|
if (!session?.user?.sub || !session?.user?.nickname) {
|
||||||
throw new Error("User session not found or incomplete")
|
redirect("/login")
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { cache } from "react"
|
import { cache } from "react"
|
||||||
import { cookies } from "next/headers"
|
import { cookies } from "next/headers"
|
||||||
|
import { redirect } from "next/navigation"
|
||||||
import { auth0 } from "@/lib/auth0"
|
import { auth0 } from "@/lib/auth0"
|
||||||
import { getUserOrganizations } from "@/components/dashboard/action"
|
import { getUserOrganizations } from "@/components/dashboard/action"
|
||||||
import type { AccountPayload } from "@codeflash-ai/common"
|
import type { AccountPayload } from "@codeflash-ai/common"
|
||||||
|
|
@ -13,7 +14,7 @@ export const getAccountContext = cache(async (): Promise<AccountPayload> => {
|
||||||
const session = await auth0.getSession()
|
const session = await auth0.getSession()
|
||||||
|
|
||||||
if (!session?.user?.sub || !session?.user?.nickname) {
|
if (!session?.user?.sub || !session?.user?.nickname) {
|
||||||
throw new Error("User session not found or incomplete")
|
redirect("/login")
|
||||||
}
|
}
|
||||||
|
|
||||||
const cookieStore = await cookies()
|
const cookieStore = await cookies()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue