Search code examples
angularfirebase-authenticationjwtangularfire2angular4-forms

Angular 4 firebase .currentUser.getToken()


How to resolve this problem?

firebase.User.prototype.getToken is deprecated.
Please use firebase.User.prototype.getIdToken instead.

Here's my code:

signinUser(email: string, password: string) {
  firebase.auth().signInWithEmailAndPassword(email, password)
  .then(
     response => {
        firebase.auth().currentUser.getToken()
           .then(
              (token: string) => this.token = token
           )
     }
  )
  .catch(
     error => console.log(error)
  );
}

Solution

  • You have to use

    firebase.auth().currentUser.getIdToken().
    

    New Firebase version had a lot of changes. you can check on the official documentation.

    https://firebase.google.com/docs/auth/android/password-auth

    Hope it helps!