Currently in the process of setting up firebase authentication.
Instead of relying on firebase's default pages for recovery password and email verification, I want to handle these processes directly on my website.
To customize the recovery steps:
- Update the default email URL in firebase to redirect users to my domain
- In the code, ensure to check for the
oobCode
useEffect(() => {
async function verifyToken() {
try {
const code = searchParams.get('code');
if (code) {
const email = await verifyPasswordResetCode(getAuth(), code);
form.setFieldValue('email', email);
form.setFieldValue('oobCode', code);
} else {
throw new Error('Missing oobCode');
}
} catch (e) {
setError(e);
} finally {
setVerifying(false);
}
}
setVerifying(true);
verifyToken();
}, []);
- Proceed with confirming password reset
const submitHandler = useCallback(
async ({ oobCode, password }: FormType) => {
setLoading(true);
try {
await confirmPasswordReset(getAuth(), oobCode, password);
setPasswordChange(true);
} catch (e) {
setError(e);
} finally {
setLoading(false);
}
},
[setLoading]
);
When it comes to email verification, there is still an oobCode
that needs validation. However, the method to confirm this code seems unclear. Should I use verifyPasswordResetCode
again or is there another function I should be utilizing?