【问题标题】:Error with admin firebase: "admin.auth(...).generatePasswordResetLink is not a function"管理员 firebase 出错:“admin.auth(...).generatePasswordResetLink 不是函数”
【发布时间】:2019-01-31 13:15:53
【问题描述】:

我通过 Node.js(nodemailer) 和 firebase 提供了电子邮件服务。

当我在应用程序中创建新用户时,该新用户应该会收到带有重置密码链接的欢迎电子邮件。

现在我需要在 node.js 中实现 firebase admin --generatePasswordResetLink

这行代码有问题,错误是 generatePasswordResetLink() 不是函数:

admin.auth().generatePasswordResetLink(user.email, actionCodeSettings)

// Create user
async function createUser(user) {
  firebase
    .auth()
    .createUser({
      email: user.email,
      password: user.password,
      displayName: `${user.firstName} ${user.lastName}`
    })
// After user is created make a email teamplate and send it
    .then(function(userRecord) {
      let resetLink = ''    
      // Welcome email template
      const output = `
        <p>You have access to the Church Mutual Assignment Tool.</p>
        <p>Follow this link to create new password for your account ${userRecord.email}:</p>
        <p>${this.resetLink}</p>
        <p>Thanks,</p>
        <p>Your Church Mutual Assignment Tool team</p>
      `
      let message = {
        from: 'nyik6nntutmq3vz6@ethereal.email',
        to: `${user.email}`,
        subject: 'Welcome to the Church Mutual Assignment Tool',
        text: 'Plaintext version of the message',
        html: output
      }


      // Generate reset password and Send Email
 //===== HERE IS PROBLEM THIS generatePasswordResetLink() "is not a fucntion"====== \\
      admin.auth().generatePasswordResetLink(user.email, actionCodeSettings)
        .then(link => {
          // Send Email
          transport.sendMail(message, (err, info) => {
            if (err) throw new Error('Error with email', err)
          })
          return sendCustomPasswordResetEmail(user.email, user.displayName, link)
        })
        .catch(error => {
          console.log('error', error)
        })
    })
}

【问题讨论】:

  • 什么是admin
  • admin 是 "const admin = require('firebase-admin')"
  • 执行console.log(admin.auth()) 以查看generatePasswordResetLink() 是否在其中,但根据错误似乎不是。

标签: node.js firebase firebase-authentication firebase-admin


【解决方案1】:

您很可能正在使用

在此处查看 Firebase Admin Node.js SDK 发行说明:https://firebase.google.com/support/release-notes/admin/node。 “用于为密码重置、电子邮件验证和电子邮件链接登录创建链接的电子邮件操作链接生成 API”仅在 2018 年 11 月添加,版本为 6.2.0。

【讨论】:

    猜你喜欢
    • 2018-09-09
    • 1970-01-01
    • 2020-08-24
    • 2018-10-30
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    相关资源
    最近更新 更多