Firebase Email Verification at Signup

Send email verification link not working in firebase auth expo

The user must be logged in to request a verification email. It seems you are trying to verify user's email before logging them in or even creating their account at first place which is not possible at the moment. So the flow should be:

// 1. Create user account / log user in
firebase.auth().createUserWithEmailAndPassword(emailID, password).then(async ({user}) => {
// 2. Send verification email
await user.sendEmailVerification()
console.log("Verification email sent!")
})

You can use emailVerified property in app to alert user if they have not verified email yet and restrict their access using security rules.
Also checkout:

Firebase Authentication: Verify email before sign up

Firebase email verification at SignUp

Custom Firebase Email Verification Template and Action Handler

I have achieved this by creating the user and generating the link on the backend with the admin SDK.

So your frontend would call a callable function or bespoke API endpoint for instance for the registration instead of using the SDK directly.

The callable would go about this:

  • Creating the user in Auth: auth.createUser()
  • Creating the user in your DB (Firestore, Mongo etc.)
  • Assigning custom claims if required: auth.setCustomUserClaims
  • Building the link for signin: auth.generateSignInWithEmailLink()
  • Sending the email to an email transactional API

You will need an ESP e.g Sendgrid, MailChimp, MailGun etc. for the last step. There you will have all the freedom to build your own templates.

Please note that the generateSignInWithEmailLink will take care of verifying an email address and signing-in. It could therefore be used for login and registration.

Cheers

Firebase send email verification to user

Is there anyway to send a verification email without signing in ?

Verification emails can only be sent from the client-side SDK, and only after the user has signed in. This is done to prevent the ability to abuse Firebase's servers for sending spam.

If the existing email verification flow of Firebase doesn't fit your needs, you can implement your own custom flow and use the Admin SDKs to set the the verification status once they've met your verification requirements.

How to first sent email verification in firebase and then create account?

When you create an account on Firebase Authentication, that user is automatically signed in. There is no way to prevent that, and this is the intended behavior.

If you want to only allow the user access to certain screens in your app after they verified their email address, you can check isEmailVerified in your code before navigating to that screen.

If you want to prevent the unverified user from accessing certain data in your (Firebase Realtime Database, Cloud Firestore, or Cloud Storage) backend, you can check the user's token in your security rules to ensure their email address is verified.



Related Topics



Leave a reply



Submit