"use client"; import { Suspense, useEffect, useState } from "react"; import Link from "next/link"; import { useSearchParams } from "next/navigation"; import { auth, AuthError } from "@/lib/auth"; import { useAuth } from "@/components/auth/auth-provider"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; function VerifyEmailContent() { const params = useSearchParams(); const token = params.get("token") ?? ""; const { refresh } = useAuth(); // Seed straight from the token's presence so the missing-token case isn't // a synchronous setState inside the effect below. const [status, setStatus] = useState<"pending" | "ok" | "error">( token ? "pending" : "error", ); const [message, setMessage] = useState( token ? "" : "Verification link is missing a token.", ); useEffect(() => { if (!token) return; void (async () => { try { await auth.verifyEmail(token); // Pull the freshly-verified user so the banner disappears immediately. await refresh(); setStatus("ok"); } catch (err) { setStatus("error"); setMessage(err instanceof AuthError ? err.message : "Verification failed."); } })(); }, [token, refresh]); return (
{status === "pending" ? "Verifying your email…" : status === "ok" ? "Email verified ✓" : "Verification failed"} {status === "pending" ? "One moment." : status === "ok" ? "Thanks — your email is confirmed." : message} Back to home
); } export default function VerifyEmailPage() { return ( ); }