1
votes

How should I go about verifying an email address prior to the user signing up with Firebase? I know that an email address is verified with .sendEmailVerification, however this only works on the current user. Hence a user must be already created before sending a verification email. This would not be of much help since you obviously have to verify an email before adding it to your database. Therefore, what is a good workaround?

1

1 Answers

2
votes

You can't verify the email prior to sign up with Firebase Auth. Email verification is not always required. This is why Firebase Auth provides it as a method on the user. Some applications do not require email verification on sign-up, others may make it optional, others may offer limited access to unverified users, etc.

If you want to require users to be verified before accessing your app content, you can either: enforce that via Firebase rules, eg: ".read": "auth.token.email_verified === true"

Or, if you are using your own backend, use the Firebase Admin SDK, https://firebase.google.com/docs/auth/admin/verify-id-tokens:

admin.auth().verifyIdToken(idToken).then(decodedToken => {
  if (decodedToken.email_verified) {
    // Email verified. Grant access.
  } else {
    // Email not verified. Ask user to verify email.
  }
});