page.tsx80 lines, 2.1 KB
| 1 | "use client"; |
| 2 | |
| 3 | import { |
| 4 | Card, |
| 5 | CardContent, |
| 6 | CardDescription, |
| 7 | CardHeader, |
| 8 | CardTitle, |
| 9 | } from "@/components/ui/card"; |
| 10 | import { Loader2 } from "lucide-react"; |
| 11 | import { apiClient } from "@/lib/api/client"; |
| 12 | import { useRouter, useSearchParams } from "next/navigation"; |
| 13 | import { Suspense, useEffect } from "react"; |
| 14 | import { toast } from "sonner"; |
| 15 | |
| 16 | function VerifyEmailContent() { |
| 17 | const searchParams = useSearchParams(); |
| 18 | const router = useRouter(); |
| 19 | const token = searchParams.get("token"); |
| 20 | |
| 21 | useEffect(() => { |
| 22 | if (!token) { |
| 23 | toast.error("Invalid verification link"); |
| 24 | router.push("/auth/login"); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | const verifyEmail = async () => { |
| 29 | try { |
| 30 | await apiClient.get(`/auth/verify-email?token=${token}`); |
| 31 | toast.success("Email verified successfully"); |
| 32 | router.push("/auth/login?verified=true"); |
| 33 | } catch (error: Error | unknown) { |
| 34 | toast.error( |
| 35 | (error as { response?: { data?: { message?: string } } })?.response |
| 36 | ?.data?.message || "Something went wrong" |
| 37 | ); |
| 38 | router.push("/auth/login"); |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | verifyEmail(); |
| 43 | }, [token, router]); |
| 44 | |
| 45 | return ( |
| 46 | <Card className="w-full max-w-[400px] mx-auto"> |
| 47 | <CardHeader> |
| 48 | <CardTitle>Email Verification</CardTitle> |
| 49 | <CardDescription> |
| 50 | Please verify your email to continue using our platform |
| 51 | </CardDescription> |
| 52 | </CardHeader> |
| 53 | <CardContent className="flex items-center justify-center"> |
| 54 | <Loader2 className="size-4 animate-spin" /> |
| 55 | </CardContent> |
| 56 | </Card> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | export default function VerifyEmailPage() { |
| 61 | return ( |
| 62 | <Suspense |
| 63 | fallback={ |
| 64 | <Card className="w-full max-w-[400px] mx-auto"> |
| 65 | <CardHeader> |
| 66 | <CardTitle>Email Verification</CardTitle> |
| 67 | <CardDescription> |
| 68 | Please wait while we verify your email |
| 69 | </CardDescription> |
| 70 | </CardHeader> |
| 71 | <CardContent className="flex items-center justify-center"> |
| 72 | <Loader2 className="size-4 animate-spin" /> |
| 73 | </CardContent> |
| 74 | </Card> |
| 75 | } |
| 76 | > |
| 77 | <VerifyEmailContent /> |
| 78 | </Suspense> |
| 79 | ); |
| 80 | } |