I'm working on an app and I want to achieve this. When an user signing in I want to get his username and store in firebase. So I created 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 this works, now I need to save also displayName into current user, so I try 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 it gives me this :
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'm running on ionic 2 angular2, firebase/angulrfire
Doc ref :
Update a user's profile
You can update a user's basic profile information—the user's display name and profile photo URL—with 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 happened. });