mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
fix: use redirect instead of throw for auth failures during prerender
Pages that throw Error("Authentication required") crash the Next.js
build during static prerendering (no auth session at build time).
redirect("/login") is a proper Next.js bailout signal that skips
prerendering and marks the route as dynamic.
This commit is contained in:
parent
c1b0076cb8
commit
09ed4d4b44
2 changed files with 5 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { Suspense } from "react"
|
||||
import { type JSX } from "react"
|
||||
import { redirect } from "next/navigation"
|
||||
import { auth0 } from "@/lib/auth0"
|
||||
import { CreateApiKeyDialog } from "./dialog-create-api-key"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
|
|
@ -109,9 +110,9 @@ async function getCachedApiKeys(userId: string): Promise<ApiKeyWithOrg[]> {
|
|||
|
||||
async function APIKeyContent(): Promise<JSX.Element> {
|
||||
const session = await auth0.getSession()
|
||||
// Auth handled by middleware + layout
|
||||
// Auth handled by middleware + layout; redirect bails out of prerendering
|
||||
if (!session?.user) {
|
||||
throw new Error("Authentication required")
|
||||
redirect("/login")
|
||||
}
|
||||
const userId = session.user.sub
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"use server"
|
||||
|
||||
import { auth0 } from "@/lib/auth0"
|
||||
import { redirect } from "next/navigation"
|
||||
import { cache } from "react"
|
||||
import { isTeamMemberCheck, isMembenchAllowed } from "@/lib/team-members"
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ export async function requireTeamMember(): Promise<void> {
|
|||
const session = await getCachedSession()
|
||||
|
||||
if (!session?.user) {
|
||||
throw new Error("Authentication required")
|
||||
redirect("/login")
|
||||
}
|
||||
|
||||
if (!isTeamMemberCheck(session.user)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue