簡體   English   中英

無法讀取null的屬性“ updatePassword”

[英]Cannot read property 'updatePassword' of null

我正在使用Firebase,並且正在嘗試遵循文檔以允許客戶在登錄時更新其密碼,但是我一直收到以下錯誤:

updatePassword.js:10 Uncaught TypeError: Cannot read property 'updatePassword' of null
    at HTMLButtonElement.<anonymous> (updatePassword.js:10)
    at HTMLButtonElement.dispatch (jquery-3.3.1.js:5183)
    at HTMLButtonElement.elemData.handle (jquery-3.3.1.js:4991)

我知道有一個值,因為我將值打印到了控制台。 有人知道發生了什么嗎?

HTML:

<h6>update password</h6>
<input id="updatePasswordField" class="updatePassword" contenteditable="true" />
<button id="updatePasswordBtn">Update Password</button>

JS

var user = firebase.auth().currentUser;

$(document).ready(function(){
  $("#updatePasswordBtn").click(function(){
    var password = $("#updatePasswordField").val();

    user.updatePassword(password).then(function() {
      // Update successful.
      console.log('updated');
    }, function(error) {
      // An error happened.
      console.log('failed update');
    });
  });
});

在做一個console.log(error.message); 我能夠弄清楚發生了什么。 我需要做的就是再次重新驗證用戶身份。 因此,我添加了一個新的輸入字段,並要求輸入他們當前的密碼,並將上面的代碼片段放在reauthenticateAndRetrieveDataWithCredential()函數中。

在此處的更多信息重新驗證用戶

https://firebase.google.com/docs/auth/web/manage-users#set_a_users_password

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM