import { useEffect } from "react"; import { useNavigate, useSearch } from "@tanstack/react-router"; import { LogIn, AlertCircle } from "lucide-react"; import { BUTTON_BASE_CLASSES, BUTTON_SIZE_CLASSES, BUTTON_VARIANT_CLASSES, } from "@/client/components/ui/button-classes"; import { useDocumentTitle } from "@/client/hooks/use-document-title"; import { useAuthStore, selectIsAuthenticated } from "@/client/stores/auth-store"; const ERROR_MESSAGES: Record = { oidc_session_expired: "Your sign-in session expired. Please try again.", oidc_provider_error: "The identity provider returned an error. Please try again.", oidc_unverified_email: "Your tessera email is not verified yet. Verify it and retry.", oidc_post_callback_refresh_failed: "Sign-in completed but the session could not be confirmed. Please try again.", tessera_email_conflict: "That email is already used by another account.", identity_conflict: "This identity could not be linked. Contact support.", }; function describeError(code: string | undefined): string | null { if (!code) return null; return ERROR_MESSAGES[code] ?? "Sign-in failed. Please try again."; } function buildOidcStartUrl(returnTo: string | undefined): string { const target = returnTo && returnTo.startsWith("/") ? returnTo : "/"; const params = new URLSearchParams({ return_to: target }); return `/api/v1/oidc/start?${params.toString()}`; } export function LoginPage() { const navigate = useNavigate(); const { redirect: redirectTo, error } = useSearch({ from: "/login" }); const isAuthenticated = useAuthStore(selectIsAuthenticated); useDocumentTitle("Login"); useEffect(() => { if (!isAuthenticated) return; navigate({ to: redirectTo || "/" }); }, [isAuthenticated, navigate, redirectTo]); const errorMessage = describeError(typeof error === "string" ? error : undefined); const oidcStartUrl = buildOidcStartUrl(typeof redirectTo === "string" ? redirectTo : undefined); return (

Welcome back

Sign in to your bland account

{errorMessage && ( )} Sign in with tessera

Have an invite link? Paste it in your browser to join a workspace.

); }