簡體   English   中英

Firebase 獲取當前用戶密碼

[英]Firebase get current user password

我有用戶個人資料頁面。 在那里我有三個字段。 姓名、電子郵件、密碼。 我可以獲取姓名和電子郵件,但無法獲取用戶密碼。 如何獲取用戶密碼並將其存儲在 v-model 指令中。

<template>
  <div class="profile-outer">
      <input type="text" v-model="profile.name">
      <input type="email" v-model="profile.email">
      <input type="password" v-model="profile.password">
  </div>
</template>


data() {
    return {
      profile: {
        name: '',
        email: '',
        password: '',
      }
    };
  }


created() {
    firebase.auth().onAuthStateChanged(user => {
      if (user) {
        this.profile.email = user.email;
        this.profile.name = user.displayName;
        console.log(user);
      } else {
      }
    })
  },

使用onAuthStateChanged()方法,您可以在回調函數中獲得一個User並且無法從這個 User 對象中獲得用戶密碼。

實際上,出於安全原因,使用客戶端 SDK,您無法獲取用戶密碼。

如果您真的希望能夠從應用程序前端獲取用戶的密碼,您可以將其保存在特定的數據庫記錄中。 但是,在這種情況下,您需要實現自己的密碼更新機制(例如通過 Cloud Function)以避免“真實”用戶密碼與存儲在數據庫記錄中的密碼之間的不同步。 例如,如果用戶可以執行sendPasswordResetEmail()方法,則不會使用新密碼值更新數據庫文檔。

最后,請注意,如果您選擇這種方法,您應該注意使用安全規則正確保護用戶(數據庫)記錄。

暫無
暫無

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

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