import { redirect } from "next/navigation"; import { SiteHeader } from "@/components/public/site-header"; import { isAuthorizedAdmin } from "@/lib/auth/authorization"; import { getCustomerSession, isSudlohOidcEnabled } from "@/lib/auth/server"; import { safeAuthReturnPath } from "@/lib/auth/return-path"; import { AccountForm } from "./account-form"; import { SudlohSignInRedirect } from "./sudloh-sign-in-redirect"; export async function AccountPage({ mode, next, verified, verificationError, oidcError }: { mode: "login" | "register"; next: unknown; verified?: boolean; verificationError?: boolean; oidcError?: string; }) { const nextPath = safeAuthReturnPath(next); const session = await getCustomerSession(); if (session) { if (nextPath.startsWith("/admin") && !isAuthorizedAdmin(session.user)) redirect("/"); redirect(nextPath); } const siteKey = process.env.TURNSTILE_SITE_KEY ?? ""; const oidcEnabled = isSudlohOidcEnabled(); const oidcOnly = oidcEnabled && process.env.SUDLOH_OIDC_ONLY === "true"; if (mode === "login" && oidcEnabled && !oidcError) { return
; } if (!oidcOnly && process.env.NODE_ENV !== "development" && !siteKey) throw new Error("TURNSTILE_SITE_KEY is required"); return
; }