const user = getAuth().currentUser;
const [emailVerified, setEmailVerified] = useState(user?.emailVerified);
let timeoutId : any;
useEffect(() => {
if (emailVerified) return;
const onIdTokenChangedUnsubscribe = getAuth().onIdTokenChanged((user) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
if (user && user.emailVerified) {
console.log("verified");
setEmailVerified(user.emailVerified);
return onIdTokenChangedUnsubscribe();
}
timeoutId = setTimeout(() => {
console.log("unverified");
getAuth().currentUser?.reload();
}, 10000);
});
}, []);