UpdateProfile () during Firebase duel

I am working on an application and I want to achieve this. When a user signs up, I want to get his username and store it in firebase. So I create this:

 Signup(email: string, password: string, displayName: string) {
    this.angFire.auth.createUser({
      email: email,
      password: password
    }).catch(
      (err) => {
        console.log(err);
        this.error = err;
      })
........

      

And it works, now I need to store the displayName in the current user as well, so I am trying to do this inside the same function (Singup ()):

let user = firebase.auth().currentUser;
    user.updateProfile({
      displayName: this.displayName,
      photoURL: "https://example.com/jane-q-user/profile.jpg"
    }).then(function() {
      console.log("Nome utente inserito");
    }, function(error) {
      console.log("Errore durante inserimento utente");
    });

      

But this gives me the following:

error_handler.js:54 EXCEPTION: Error in ./SignupPage class SignupPage - inline template:70:4 caused by: Cannot read property 'updateProfile' of null

      

How to do it? I am working on ionic 2 angular2, firebase / angulrfire

Doc ref:

Update user profile

You can update the basic user profile information - displaying the user's name and profile URL using the updateProfile method. For example:

var user = firebase.auth (). currentUser;

user.updateProfile ({displayName: "Jane Q. User", photoURL: " https://example.com/jane-q-user/profile.jpg "}) then (function () {
// Update successful.} , function (error) {// An error occured.});

here

+3


source to share





All Articles