"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { CheckCircle2, LoaderCircle, ShieldCheck, XCircle } from "lucide-react"; import { Brand } from "./Brand"; type VerificationState = "verifying" | "verified" | "invalid"; export function VerifyEmail({ token }: { token: string }) { const [state, setState] = useState(token ? "verifying" : "invalid"); const [message, setMessage] = useState(token ? "Confirming your email address…" : "This verification link is incomplete."); useEffect(() => { if (!token) return; let active = true; fetch("/api/auth/verification/confirm", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ token }), }) .then(async (response) => { const result = await response.json() as { error?: string }; if (!response.ok) throw new Error(result.error ?? "This verification link is invalid or expired."); if (active) { setState("verified"); setMessage("Your LinkedIn account is verified and ready."); } }) .catch((error: unknown) => { if (active) { setState("invalid"); setMessage(error instanceof Error ? error.message : "This verification link is invalid or expired."); } }); return () => { active = false; }; }, [token]); const Icon = state === "verifying" ? LoaderCircle : state === "verified" ? CheckCircle2 : XCircle; return (

{state === "verifying" ? "Verifying email" : state === "verified" ? "Email verified" : "Link unavailable"}

{message}

{state === "verified" ? ( Continue to LinkedIn ) : state === "invalid" ? ( Return to sign in ) : null}
); }