Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send email verification code to user email in firebase

I want to send email verification code to user's email using firebase authentication. I am using (sendEmailVerification) method but firebase sends a verification link to user's email. Is it possible to send verification code to user's email if yes then how it can be done?

I am using Angular 4 and for firebase angularfire2

Thanks.

like image 891
harry Avatar asked Aug 22 '17 07:08

harry


People also ask

Does Firebase charge for email verification?

The first 10K verifications for both instances (USA, Canada, and India and All other countries) are provided at no cost each month. You are only charged on usage past this no-cost allotment. Prices are per successful verification.

Can we send OTP using Firebase?

You can use Firebase Authentication to enable a user to sign in to your app by sending an SMS to user's device which contains a one-time-password. The user then enters this OTP in your app, if the OTP matches then sign in is successful and the user can then access your app.

Can Firebase be used for authentication?

You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.


1 Answers

If don´t want to use the solution provided by firebase, you have to handle all the process yourself and then update the user emailVerified data to true.

The basic 3 steps are:
1. send an email to the user with "whatever code" you want
2. in your logic, validate the "code" typed by the user
3. use Firebase Admin SDK to update the user (you can only update this user property using the Admin SDK)

Step 3 example, using NodeJS

admin.auth().updateUser(uid, {emailVerified:true})
  .then(function(userRecord) {
      console.log("update success", userRecord.toJSON());
  })
  .catch(function(err) {
      console.log("Error updating user", err);
  });
like image 95
guillefd Avatar answered Sep 28 '22 09:09

guillefd