2017-09-25 28 views
1

我想使用Vuejs重置密码。我设法通过自定义网址发送重置密码链接,当用户点击它时,它会重定向到自定义表单。密码重置网址是:使用VueJs在Firebase上重置密码

http://localhost:8080/passwordreset?mode=resetPassword&oobCode=viIqct7-jvuNnZxMEgyyRualxpX5CmZ3_EJrCQi-C88AAAFeuLXmWg&apiKey=AIzaSyBaCCvq-ZEfQmdrL7fmElXDjZF_J-tku2I

<input type="password" v-model="passwordNew" class="" placeholder="New password"> 

<input type="password" v-model="passwordConfirm"class=""placeholder="Confirm Password"> 

<button class="btn" v-on:click="resetPassword">Reset Password</button> 

我的密码重置文件为component,在我<script>我有:

import firebase from 'firebase' 
export default { 

    data: function() { 
     return { 
      passwordNew: '', 
      passwordConfirm: '', 
     } 
    }, 
    methods: { 
     resetPassword: function() { 
      var newPassword = this.passwordNew 

      var user = firebase.auth().currentUser; 
      console.log (" User: "+ user); 

      user.updatePassword(newPassword).then(function() { 
       // Update successful. 
       alert("Reset Password successful") 
      }).catch(function(error) { 
       // An error happened. 
      }); 

     }, 
     checkPasswords: function() { 

     } 
    } 

} 

我得到的,当用户设置新的密码是该用户为空的控制台,请参阅下图:

enter image description here

回答

0

您正在使用此错误。 发送重置密码邮件时,表示用户未登录。更新密码时,用户已登录。 对于您的情况,您需要拨打auth.confirmPasswordReset(code, newPass)。欲了解更多关于此API,检查:https://firebase.google.com/docs/reference/js/firebase.auth.Auth#confirmPasswordReset

更多关于构建自己的密码重置登陆页面,检查:https://firebase.google.com/docs/auth/custom-email-handler

+0

嗯,我需要一个示例代码,以帮助我,我应该删除我的所有实现的代码和使用该文档中的示例:https://firebase.google.com/docs/auth/custom-email-handler – Muli