且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Firebase中将电子邮件验证码发送到用户电子邮件

更新时间:2023-12-01 17:50:16

如果不想使用firebase提供的解决方案,则必须自己处理所有过程,然后将用户emailVerified数据更新为.

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.

基本的3个步骤是:
1.向您发送一封电子邮件,其中包含您想要的任何代码"
2.在您的逻辑中,验证用户键入的代码"
3. 使用Firebase Admin SDK更新用户 (您只能使用Admin SDK更新此用户属性)

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)

第3步示例,使用NodeJS

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