How to send email verification code to user email in firebase

僤鯓⒐⒋嵵緔 提交于 2019-12-23 02:21:03

问题


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.


回答1:


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);
  });



回答2:


Firebase Auth now supports the ability to pass state/continue URL in the email verification flow: https://firebase.google.com/docs/auth/web/passing-state-in-email-actions (web and iOS, with Android on the way). The codes are pretty long unlike the 6 digit SMS codes. So copying the code, especially if you open the email on a different device is not feasible.



来源:https://stackoverflow.com/questions/45811741/how-to-send-email-verification-code-to-user-email-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!