With OIDC_ISSUER, OIDC_CLIENT_ID and OIDC_CLIENT_SECRET empty (or at the .env.example placeholders) Kaname needs no login. With all three set, OIDC works as before; only some set is an error. /api/v1 still requires tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
2.2 KiB
TypeScript
56 lines
2.2 KiB
TypeScript
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<string, string> = {
|
|
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 (
|
|
<main className="flex min-h-screen items-center justify-center p-4">
|
|
<Card className="w-full max-w-sm">
|
|
<CardHeader>
|
|
<CardTitle className="text-lg">Kaname</CardTitle>
|
|
<CardDescription>Sign in to manage local models.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="flex flex-col gap-3">
|
|
{error && (
|
|
<p role="alert" className="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
|
{error}
|
|
</p>
|
|
)}
|
|
<form
|
|
action={async () => {
|
|
"use server";
|
|
await signIn(OIDC_PROVIDER_ID, { redirectTo: callbackUrl });
|
|
}}
|
|
>
|
|
<Button type="submit" className="w-full" size="lg">
|
|
Sign in with Pocket ID
|
|
</Button>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
</main>
|
|
);
|
|
}
|