"use client"; import { useState } from "react"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { ArrowRight, Lock, Mail, Shield } from "lucide-react"; import { AuthCard, AuthCardHeader, AuthPageShell, } from "~/components/auth/auth-page-shell"; import { LegalAgreementNotice } from "~/components/legal/legal-links"; import { Button } from "~/components/ui/button"; import { Input } from "~/components/ui/input"; import { Label } from "~/components/ui/label"; import { env } from "~/env"; import { authClient } from "~/lib/auth-client"; import { toast } from "sonner"; interface SignInFormProps { allowRegistration: boolean; } export function SignInForm({ allowRegistration }: SignInFormProps) { const authentikEnabled = env.NEXT_PUBLIC_AUTHENTIK_ENABLED === true; const router = useRouter(); const searchParams = useSearchParams(); const callbackUrl = searchParams.get("callbackUrl") ?? "/dashboard"; const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); async function handleSignIn(e: React.FormEvent) { e.preventDefault(); setLoading(true); const { error } = await authClient.signIn.email({ email, password }); setLoading(false); if (error) { toast.error( error.message && error.message !== "Required" ? error.message : "Invalid email or password", ); return; } toast.success("Signed in successfully!"); router.push(callbackUrl); router.refresh(); } async function handleSocialSignIn() { setLoading(true); try { await authClient.signIn.oauth2({ providerId: "authentik", callbackURL: callbackUrl, }); } catch (error) { console.error("[SSO Error]", error); setLoading(false); } } return ( {!allowRegistration && (

New account registration is currently disabled.

)} {authentikEnabled && (
or
)}
setEmail(e.target.value)} required autoFocus autoComplete="email" className="h-11 pl-10" placeholder="you@example.com" />
Forgot password?
setPassword(e.target.value)} required autoComplete="current-password" className="h-11 pl-10" placeholder="••••••••" />
{allowRegistration && (

Don't have an account?{" "} Create account

)}
); }