【问题标题】:Firebase get current user passwordFirebase 获取当前用户密码
【发布时间】:2020-03-29 15:34:31
【问题描述】:

我有用户个人资料页面。在那里我有三个领域。姓名、邮箱、密码。我可以获取姓名和电子邮件,但无法获取用户密码。如何获取用户密码并将其存储在 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 {
      }
    })
  },

【问题讨论】:

    标签: firebase vue.js firebase-authentication


    【解决方案1】:

    使用onAuthStateChanged() 方法,您可以在回调函数中获得User,并且无法从此用户对象中获取用户密码。

    实际上,出于安全原因,使用客户端 SDK,您无法获取用户密码。

    如果您真的希望能够从应用程序前端获取用户密码,您可以将其保存在特定的数据库记录中。但是,在这种情况下,您需要实现自己的密码更新机制(例如通过 Cloud Function),以避免“真实”用户密码与存储在数据库记录中的密码不同步。例如,如果用户可以执行sendPasswordResetEmail() 方法,数据库文档将不会更新为新密码值。

    最后,请注意,如果您选择此方法,则应注意使用安全规则正确保护用户(数据库)记录。

    【讨论】:

      猜你喜欢
      • 2018-06-03
      • 2020-11-30
      • 1970-01-01
      • 2019-05-27
      • 2017-04-06
      • 1970-01-01
      • 2021-03-05
      • 2020-03-03
      • 1970-01-01
      相关资源
      最近更新 更多