RAHUL KUNDU
RAHUL KUNDU

Reputation: 881

Firebase get current user password

I have user profile page. In there I have three fields. Name, Email, password. I can fetch the name and email but I can get not be able to the user password. how can I get the user password and store it in the v-model directive.

<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 {
      }
    })
  },

Upvotes: 3

Views: 4078

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83093

With the onAuthStateChanged() method you get a User in the callback function and there is no way, from this User object, to get the user password.

Actually, for security reasons, with the clients SDKs, you cannot get the user's password.

If you really want to be able to get the user's password from an app front-end, you could save it in a specific database record. However, in this case you will need to implement your own password update mechanism (for example through Cloud Function) to avoid a de-synchronization between the "real" user password and the one stored in the DB record. For example, if the user can execute the sendPasswordResetEmail() method, the database document will not be updated with the new password value.

Finally, note that if you choose this approach, you should take care to correctly secure the user (database) record with security rules.

Upvotes: 3

Related Questions