Firebase Returning user object after account creation
Looks like firebase has made some changes on this method. The accepted solution needs a little fix:
firebase.auth().createUserWithEmailAndPassword(textUser, textPassword)
.then(function(data){
console.log('uid',data.user.uid)
//Here if you want you can sign in the user
}).catch(function(error) {
//Handle error
});
Now you get to acces the user via data.user
Hope this helps :)
The createUserWithEmailAndPassword()
function returns a so-called Promise, which has methods catch()
and then()
. You're already using catch()
to handle problems. To handle "non-problems", you need to use then()
:
firebase.auth().createUserWithEmailAndPassword(textUser, textPassword)
.then(function(user) {
console.log(user); // see https://firebase.google.com/docs/reference/js/firebase.User
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
return Result = "false";
// ...
});
See the reference documentation for createUserWithEmailAndPassword and for firebase.User.
In order to get the user id in the client side you should do this:
firebase.auth().createUserWithEmailAndPassword(textUser, textPassword)
.then(function(user){
console.log('uid',user.uid)
//Here if you want you can sign in the user
}).catch(function(error) {
//Handle error
});
as it is described here:
https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword
Returns non-null firebase.Promise containing non-null firebase.User