"use client"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { Suspense, useEffect, useState } from "react"; import { AuthShell, FormAlert } from "@/components/auth/auth-ui"; import { Button } from "@/components/ui/button"; import { authClient } from "@/lib/auth-client"; function VerifyEmailInner() { const router = useRouter(); const params = useSearchParams(); const email = params.get("email") ?? ""; const { data: session } = authClient.useSession(); const [notice, setNotice] = useState(null); const [error, setError] = useState(null); const [sending, setSending] = useState(false); // After the emailed link verifies the address, Better Auth auto-signs the // user in and redirects here — at which point a session exists. useEffect(() => { if (session?.user) router.replace("/"); }, [session, router]); const resend = async () => { if (!email || sending) return; setSending(true); setError(null); setNotice(null); const { error: err } = await authClient.sendVerificationEmail({ email, callbackURL: `${window.location.origin}/verify-email`, }); setSending(false); if (err) { setError(err.message ?? "Could not resend the verification email."); return; } setNotice("Verification email sent. Check your inbox."); }; return ( Back to sign in } subtitle={ email ? ( <> We sent a verification link to{" "} {email}. Open it to activate your account. ) : ( "Open the verification link we emailed you to activate your account." ) } title="Check your inbox" >
{notice && {notice}} {error && {error}} {email && ( )}
); } export default function VerifyEmailPage() { return ( ); }