From 71127055f3c22bbf082b2e347d03a727f8cd13ab Mon Sep 17 00:00:00 2001 From: Kevin Turcios Date: Mon, 13 Apr 2026 12:38:16 -0500 Subject: [PATCH] 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. --- js/cf-webapp/src/app/utils/auth.ts | 2 +- js/cf-webapp/src/lib/server/get-account-context.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/js/cf-webapp/src/app/utils/auth.ts b/js/cf-webapp/src/app/utils/auth.ts index fbc706c9f..7ea89f2b4 100644 --- a/js/cf-webapp/src/app/utils/auth.ts +++ b/js/cf-webapp/src/app/utils/auth.ts @@ -18,7 +18,7 @@ export async function getUserIdAndUsername(): Promise<{ username: string; userId const session = await getCachedSession() if (!session?.user?.sub || !session?.user?.nickname) { - throw new Error("User session not found or incomplete") + redirect("/login") } return { diff --git a/js/cf-webapp/src/lib/server/get-account-context.ts b/js/cf-webapp/src/lib/server/get-account-context.ts index 4799dd354..c41943afd 100644 --- a/js/cf-webapp/src/lib/server/get-account-context.ts +++ b/js/cf-webapp/src/lib/server/get-account-context.ts @@ -1,5 +1,6 @@ import { cache } from "react" import { cookies } from "next/headers" +import { redirect } from "next/navigation" import { auth0 } from "@/lib/auth0" import { getUserOrganizations } from "@/components/dashboard/action" import type { AccountPayload } from "@codeflash-ai/common" @@ -13,7 +14,7 @@ export const getAccountContext = cache(async (): Promise => { const session = await auth0.getSession() if (!session?.user?.sub || !session?.user?.nickname) { - throw new Error("User session not found or incomplete") + redirect("/login") } const cookieStore = await cookies()