import { redirect } from "next/navigation"; import { currentSession, OIDC_PROVIDER_ID, signIn } from "@/auth"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; const ERRORS: Record = { AccessDenied: "Your account is not in a group that is allowed to use this app.", Configuration: "Login is misconfigured. Check the server logs and the OIDC_* settings.", OAuthCallbackError: "The identity provider returned an error. Please try again.", }; /** Only allow same-origin relative paths as post-login targets. */ function safeCallback(value: string | string[] | undefined): string { const v = Array.isArray(value) ? value[0] : value; return v && v.startsWith("/") && !v.startsWith("//") ? v : "/"; } export default async function LoginPage({ searchParams }: PageProps<"/login">) { const params = await searchParams; const callbackUrl = safeCallback(params.callbackUrl); // Also covers login off: currentSession() is never null then. if (await currentSession()) redirect(callbackUrl); const errorKey = typeof params.error === "string" ? params.error : undefined; const error = errorKey ? (ERRORS[errorKey] ?? "Login failed. Please try again.") : undefined; return (
Kaname Sign in to manage local models. {error && (

{error}

)}
{ "use server"; await signIn(OIDC_PROVIDER_ID, { redirectTo: callbackUrl }); }} >
); }