【问题标题】:Firebase Web - Reset password doesn't work?Firebase Web - 重置密码不起作用?
【发布时间】:2018-02-09 08:58:44
【问题描述】:

我尝试创建重置密码页面。但是,如果我应用它向我显示的操作代码,则该代码无效。但它应该是有效的。所以我想我这样做的方式是错误的?!我还有一个验证电子邮件页面,我也在其中使用 applyActionCode,它工作正常。是的,我 100% 确定 oobCode 一定是正确的。

console.log(this.$route.query.oobCode.toString())
firebase.auth().applyActionCode(this.$route.query.oobCode.toString()).then(
    (user) => {
        cosnole.log('user', user)
        user.updatePassword(this.password).then(
            function(user) {
                console.log('password updated')
            }).catch(
            function(err) {
                console.log(err.message)
            }
        )
    }).catch(
    function(err) {
        console.log(err.message)
    }
)

【问题讨论】:

  • 您能否显示您在问题中收到的错误消息?
  • 操作码无效。如果代码格式错误、过期或已被使用,则可能会发生这种情况。

标签: node.js firebase firebase-authentication


【解决方案1】:

使用您的示例使用 firebase auth 重置用户密码时,需要了解一些事项。

applyActionCode 返回包含voidfirebase.Promise

用户来自最近通过身份验证的用户的firebase.auth().currentUserupdatePassword 还返回包含voidfirebase.Promise

可以选择使用confirmPasswordReset 将上述两者结合起来。

重要提示:代码必须是由sendPasswordResetEmail 方法生成的电子邮件返回的有效操作类型(PASSWORD_RESET

代码将类似于以下内容

firebase.auth().applyActionCode(this.$route.query.oobCode.toString())
  .then( () => {
    const user = firebase.auth().currentUser
    user.updatePassword(this.password).then(
      () => {
        console.log('password updated')
      })
   .catch(
     error => {
       console.log(error.code, error.message)
     })        
  }
  .catch(error => {
    console.log(error.code, error.message)
  })

confirmPasswordReset

firebase.auth().confirmPasswordReset(this.$route.query.oobCode.toString(), this.password)
  .then( () => {
    console.log('password updated')
  }
  .catch(error => {
    console.log(error.code, error.message)
  })

注意:我尚未确认您更新密码的代码版本,但使用了confirmPasswordReset

【讨论】:

  • 我的代码示例是为了更正您调用的假设,但正如我指出的,您可能需要在从 sendPasswordResetEmail 返回代码后使用 confirmPasswordReset
  • 谢谢。第二种方式,confirmPasswordReset,是有效的。
猜你喜欢
  • 2016-11-04
  • 1970-01-01
  • 2016-04-30
  • 2015-08-26
  • 2019-01-28
  • 2015-08-25
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多