"use client"; import { Suspense, useEffect, useState } from "react"; import { useSearchParams, useRouter } from "next/navigation"; import { Loader2, CheckCircle, XCircle } from "lucide-react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; function VerifyContent() { const searchParams = useSearchParams(); const router = useRouter(); const [status, setStatus] = useState<"loading" | "success" | "error">("loading"); const [errorMessage, setErrorMessage] = useState(""); useEffect(() => { const token = searchParams.get("token"); const error = searchParams.get("error"); if (error) { setStatus("error"); setErrorMessage(decodeURIComponent(error)); return; } if (!token) { setStatus("error"); setErrorMessage("No verification token provided"); return; } // The verification is handled by Better Auth automatically // If we reach this page with a token, it means the verification was successful // and the user should be redirected const callbackUrl = searchParams.get("callbackURL") || "/"; // Short delay to show success state setTimeout(() => { setStatus("success"); setTimeout(() => { router.push(callbackUrl); }, 1500); }, 500); }, [searchParams, router]); return (
P
{status === "loading" && "Verifying..."} {status === "success" && "Verified!"} {status === "error" && "Verification Failed"} {status === "loading" && "Please wait while we verify your magic link"} {status === "success" && "You're being redirected..."} {status === "error" && errorMessage}
{status === "loading" && ( )} {status === "success" && (
)} {status === "error" && (
)}
); } export default function VerifyPage() { return ( Loading...}> ); }