"use client" import { useEffect, useState } from "react" import Link from "next/link" import { useSearchParams } from "next/navigation" import { CheckCircle2, XCircle } from "lucide-react" type Status = "verifying" | "success" | "error" export function VerifyEmailForm() { const searchParams = useSearchParams() const token = searchParams.get("token") const [status, setStatus] = useState(token ? "verifying" : "error") const [email, setEmail] = useState(null) const [error, setError] = useState(null) useEffect(() => { if (!token) { setError("Mangler kode i lenken.") return } async function verify() { try { const res = await fetch("/auth/profile/email/confirm", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify({ token }), }) if (!res.ok) { const body = await res.json().catch(() => null) throw new Error(body?.detail?.message ?? "Lenken er ugyldig eller utløpt.") } const result: { email: string } = await res.json() setEmail(result.email) setStatus("success") } catch (err) { setError(err instanceof Error ? err.message : "Noe gikk galt. Prøv igjen.") setStatus("error") } } void verify() }, [token]) if (status === "verifying") { return (
) } if (status === "success") { return (

E-post oppdatert

{email && (

Du logger nå inn med {email}.

)}
Til kontoinnstillinger
) } return (

Kunne ikke bekrefte

{error}

Til kontoinnstillinger
) }