11"use client" ;
22
33import { useEffect , useState } from "react" ;
4- import { useRouter , useSearchParams } from "next/navigation" ;
4+ import { useSearchParams } from "next/navigation" ;
55import { MailCheck , XCircle } from "lucide-react" ;
66import { useAuth } from "@/context/auth-context" ;
77import { resendVerificationEmail , verifyEmail } from "@/lib/auth/api" ;
88import { getApiErrorMessage } from "@/lib/api-error" ;
99import { Spinner } from "@/components/ui/spinner" ;
1010import { Button } from "@/components/ui/button" ;
1111
12+ const SESSION_SYNC_RETRY_DELAYS_MS = [ 150 , 300 , 600 ] ;
13+
1214export default function VerifyEmailPage ( ) {
1315 const params = useSearchParams ( ) ;
14- const router = useRouter ( ) ;
1516 const { refetchUser } = useAuth ( ) ;
1617 const token = params . get ( "token" ) ;
1718
@@ -33,10 +34,19 @@ export default function VerifyEmailPage() {
3334 void ( async ( ) => {
3435 try {
3536 await verifyEmail ( token ) ;
36- await refetchUser ( ) ;
3737 if ( ! isMounted ) return ;
3838 setStatus ( "success" ) ;
39- redirectTimeout = setTimeout ( ( ) => router . replace ( "/explore" ) , 2500 ) ;
39+
40+ for ( const delay of SESSION_SYNC_RETRY_DELAYS_MS ) {
41+ try {
42+ await refetchUser ( ) ;
43+ break ;
44+ } catch {
45+ await new Promise ( ( resolve ) => setTimeout ( resolve , delay ) ) ;
46+ }
47+ }
48+
49+ redirectTimeout = setTimeout ( ( ) => window . location . replace ( "/explore" ) , 1200 ) ;
4050 } catch ( error ) {
4151 if ( ! isMounted ) return ;
4252 setStatus ( "error" ) ;
@@ -48,7 +58,7 @@ export default function VerifyEmailPage() {
4858 isMounted = false ;
4959 if ( redirectTimeout ) clearTimeout ( redirectTimeout ) ;
5060 } ;
51- } , [ refetchUser , router , token ] ) ;
61+ } , [ refetchUser , token ] ) ;
5262
5363 const handleResend = async ( ) => {
5464 if ( ! resendEmail || resendStatus === "sending" || resendStatus === "sent" ) return ;
0 commit comments