"use client"; import { useState } from "react"; import { auth, AuthError } from "@/lib/auth"; import { AddEmailModal } from "./add-email-modal"; import { useAuth } from "./auth-provider"; /** * Top ribbon for accounts whose email is either missing (OAuth sign-up * without an address) or present-but-unverified. * * Two modes: * • Missing email — "Add an email" button that opens AddEmailModal. * The modal POSTs to /auth/email and refreshes the user; on success * this banner flips into the verify-your-email mode automatically. * • Unverified email — "Resend verification" button calls * auth.resendVerification(). * * Renders nothing when: * - auth state is still loading * - user is logged out * - user.email_verified_at is set (the address has been confirmed) * - user dismissed it for this session (persistent across navigations * but reset on full page refresh) */ export function VerifyEmailBanner() { const { user, loading } = useAuth(); const [sent, setSent] = useState(false); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [dismissed, setDismissed] = useState(false); const [emailModalOpen, setEmailModalOpen] = useState(false); if (loading || !user || user.email_verified_at || dismissed) return null; const needsEmail = !user.email; async function onResend() { setError(null); setBusy(true); try { await auth.resendVerification(); setSent(true); } catch (err) { setError( err instanceof AuthError ? err.message : "Could not send verification email.", ); } finally { setBusy(false); } } return ( <>

{sent ? "✓ Verification email sent — check your inbox." : error ? error : needsEmail ? "Add an email to enable password recovery and notifications." : `Verify your email (${user.email}) to secure your account.`}

{!sent ? ( needsEmail ? ( ) : ( ) ) : null}
setEmailModalOpen(false)} /> ); }