/** * Login β€” two doors, one identity rule (never both at once): * * - "Continue as guest": one click, no account. A per-browser secret is * minted locally; the agent remembers this browser across visits. * - "Sign in": the BYO-OIDC seam. Rendered only when `auth.oidc` is * configured in guuey.app.json (or via `scripts/bootstrap.mjs`) β€” any * spec-compliant IdP; this is where a "Sign in with Google" plugs in. The * bound guuey app must be in BYO auth mode for the same issuer. Until it * is configured the page shows the guest door alone: a disabled * "not configured yet" control is a developer note, not a customer door * (guuey#930). */ import { useEffect, useRef, useState } from "react"; import { useNavigate } from "react-router-dom"; import { appConfig } from "../config"; import { CHAT_PATH } from "../routes"; import { continueAsGuest, setIdentityMode } from "../lib/identity"; import { completeSignIn, isSigninCallback, oidcConfigured, signIn, signOutOidc } from "../lib/oidc"; export function Login() { const navigate = useNavigate(); const [error, setError] = useState(null); const [completing, setCompleting] = useState(isSigninCallback()); // One-shot: StrictMode double-invokes effects in dev, and the OIDC // authorization code is single-use β€” a second signinCallback() would // double-spend it and flash a bogus failure. const callbackStarted = useRef(false); // Finish the redirect flow when the IdP sent us back here. useEffect(() => { if (!isSigninCallback() || callbackStarted.current) return; callbackStarted.current = true; completeSignIn() .then(() => { setIdentityMode("oidc"); navigate(CHAT_PATH, { replace: true }); }) .catch((err: unknown) => { setCompleting(false); setError(err instanceof Error ? err.message : String(err)); }); }, [navigate]); function guest() { // One identity mode per surface: an explicit guest choice also drops // any cached OIDC session, so a stale bearer can never shadow it. void signOutOidc(); continueAsGuest(); navigate(CHAT_PATH); } if (completing) { return (

Completing sign-in…

); } return (

Welcome to {appConfig.brand.name}

{oidcConfigured() ? ( ) : null}

{appConfig.copy.login.guestHint}

{error ?

Sign-in failed: {error}

: null}
); }