"use client"; /** * LoginForm — pure form widget reused by both the dedicated /login page and * the AuthGate modal that pops up when an unauthenticated user tries to use * a protected feature. * * `onSuccess` is invoked once login completes. Callers decide what happens * next (a page redirect, a modal close, etc.). The form itself doesn't * navigate — that keeps it environment-agnostic. * * `forgotPasswordHref` is configurable so the modal can override (it may * want to dismiss itself or open a different mode). */ import { useState } from "react"; import Link from "next/link"; import { useAuth } from "@/components/auth/auth-provider"; import { AuthError } from "@/lib/auth"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; export function LoginForm({ onSuccess, forgotPasswordHref = "/forgot-password", showForgotLink = true, }: { onSuccess?: () => void; forgotPasswordHref?: string; showForgotLink?: boolean; }) { const { logIn } = useAuth(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [submitting, setSubmitting] = useState(false); async function onSubmit(e: React.SyntheticEvent) { e.preventDefault(); setError(null); setSubmitting(true); try { await logIn(email, password); onSuccess?.(); } catch (err) { setError(err instanceof AuthError ? err.message : "Login failed."); } finally { setSubmitting(false); } } return (
setEmail(e.target.value)} />
{showForgotLink ? ( Forgot? ) : null}
setPassword(e.target.value)} />
{error ?

{error}

: null}
); }