"use client"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { Suspense, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { AuthShell, FormAlert } from "@/components/auth/auth-ui"; import { Button } from "@/components/ui/button"; import { authClient } from "@/lib/auth-client"; function VerifyEmailInner() { const { t } = useTranslation(); 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 ?? t("auth.verifyEmail.resendError")); return; } setNotice(t("auth.verifyEmail.resent")); }; return ( {t("common.backToSignIn")} } subtitle={ email ? t("auth.verifyEmail.subtitle", { email }) : t("auth.verifyEmail.subtitleNoEmail") } title={t("auth.verifyEmail.title")} >
{notice && {notice}} {error && {error}} {email && ( )}
); } export default function VerifyEmailPage() { return ( ); }