Reputation: 43
I have a web application created with HTMLL, CSS, JS and Firebase. I am using Firebase Authentication Email&Password verification. I can create a user acconut, but my function for adding aditional information not work. I need to save property "displayname" and "photoURL".
Here is my code in JS:
//Get current user data
var user = firebase.auth().currentUser;
user.updateProfile({
displayName: "John",
photoURL: "/images/profile.jpg"
}).then(function() {
window.location = "/dashboard.html"
console.log("Succssesly created data")
}).catch(function(error) {
alert("Something went wrong")
console.log(error)
console.log("Data create error")
});
})
Wierd is that never exception was catched. Every time console write succsses and I am redirected to dashboard.html. But when I check in console firebase.auth().currentUser object, "displayName" and "photoURL" properies are still null.
Upvotes: 1
Views: 599
Reputation: 4163
There are a few things going on:
When you update the user, the user data may not be updated locally, as this is normally decoded from the ID Token. It's actually common practice to update the client directly on success rather than force refresh requests.
I would also upgrade your functions from anonymous functions to arrow functions to bind env variables.
Upvotes: 1
Reputation: 395
You will probabily have to create another collection to store rest of the data. I was working on this a few weeks ago and found no way to store the data in the authentication section of firebase. But if you use google account (gmail) authentication then you might be able to store images as well.
So the left out option is to use another collection and store the reset of the data in that.
You can also use the logged in user identifier from firebase as the document name (as a primary key) of the second collection, that way it will be easy to locate the required data fields.
Upvotes: 0