get UID of recently created user on Firebase
firebase, firebase-security, firebasesimplelogin
Solution
Firebase recently released an updated JavaScript client (v2.0.5) which directly exposes the user id of the newly-created user via the second argument to the completion callback. Check out the changelog at https://www.firebase.com/docs/web/changelog.html and see below for an example:
ref.createUser({
email: '...',
password: '...'
}, function(err, user) {
if (!err) {
console.log('User created with id', user.uid);
}
});
Problem
Is there a way to get the UID of a recently created user? According to createUser() documentation, it doesn't look like it returns anything. How would one go about obtaining this information so that we can start storing information about the user? I know a way that could be achieved would be logging in the user upon creation. But I don't want to overwrite my existing session. ``` var firebaseRef = new Firebase('https://samplechat.firebaseio-demo.com'); firebaseRef.createUser({ email : "bobtony@firebase.com", password : "correcthorsebatterystaple" }, function(err) { if (err) { switch (err.code) { case 'EMAIL_TAKEN': // The new user account cannot be created because the email is already in use. case 'INVALID_EMAIL': // The specified email is not a valid email. case default: } } else { // User account created successfully! } }); ```