diff --git a/frontend/src/pages/Register.tsx b/frontend/src/pages/Register.tsx index 6dbb768..ffa416e 100644 --- a/frontend/src/pages/Register.tsx +++ b/frontend/src/pages/Register.tsx @@ -3,6 +3,7 @@ import { Button, TextInput, TextArea } from '@components'; import { register, signin, RegisterError, ApiError } from '@services'; import { useAuth } from '@/contexts/AuthContext'; import { useNavigate } from 'react-router-dom'; +import { getApiUrl } from '@/utils'; type RegistrationStep = | 'login-register' @@ -214,24 +215,80 @@ const Register = () => { ); - const renderVerifyEmail = () => ( -
-

Verify your account

-

- Your account and wallet has been linked. We just sent an email - confirmation to{' '} - {formData.email}. Please - verify your account to continue registering. -

- -
- Didn't get the email? - + const renderVerifyEmail = () => { + useEffect(() => { + let isMounted = true; + + const checkVerification = async () => { + try { + const response = await fetch( + getApiUrl(`/auth/ami-verified?email=${encodeURIComponent(formData.email)}`), + { method: 'GET' } + ); + + const data = await response.json(); + + if (data.verified && isMounted) { + setCurrentStep('signing-in'); + } + } catch (error) { + console.error('error checking verification status', error); + } + }; + + let intervalId: ReturnType | null = null; + + const handleVisibilityChange = () => { + if (document.hidden) { + if (intervalId) { + clearInterval(intervalId); + intervalId = null; + } + } else { + if (!intervalId) { + checkVerification(); + intervalId = setInterval(checkVerification, 1000); + } + } + } + + document.addEventListener('visibilitychange', handleVisibilityChange); + + if (!document.hidden) { + checkVerification(); + intervalId = setInterval(checkVerification, 1000); + } + + return () => { + isMounted = false; + + if (intervalId) { + clearInterval(intervalId); + } + + document.removeEventListener('visibilitychange', handleVisibilityChange); + }; + }, [formData.email]); + + return ( +
+

Verify your account

+

+ Your account and wallet has been linked. We just sent an email + confirmation to{' '} + {formData.email}. Please + verify your account to continue registering. +

+ +
+ Didn't get the email? + +
-
- ); + ); + }; const renderSigningIn = () => { useEffect(() => {