Firebase v3 Offers Authentication via 3rd party oAuth providers, facebook, github,google, and twitter. They also offer password pased authentication.
Authenticated users have a firebase.User object with 4 key properties - displayName, email, photoURL. A password is required to sign in and to register.
In oAuth, the email, displayName, and photoUrl are gotten from the oAuth provider. Developers must enter this in the Firebase v3 Auth system via an .updateProfile
method for Password based users.
So, for registering new users, I collect the 4 values from <inputs>
and call the below homemade function to register the new user with all the values in one go. Promise chaining was used. Any missing arguments must be null
(not undefined
prior to invoking the firebase methods).
Is there a cleaner way to chain these or does this look fairly solid. I know it works. I'm just seeing if it can be smartened up a bit.
createUserWithEmailAndPassword
createUserWithEmailAndPassword(email, password)
returns firebase.Promise
containing non-null firebase.User
. Creates a new user account associated with the specified email address and password.
updateProfile
var profile = {displayName: nullable string, photoURL: nullable string};
updateProfile(profile)
returns firebase.Promise
containing void
. Updates a user's profile data.
function registerPasswordUser(email,displayName,password,photoURL){
var user = null;
//nullify empty arguments
for (var i = 0; i < arguments.length; i++) {
arguments[i] = arguments[i] ? arguments[i] : null;
}
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function () {
user = firebase.auth().currentUser;
user.sendEmailVerification();
})
.then(function () {
user.updateProfile({
displayName: displayName,
photoURL: photoURL
});
})
.catch(function(error) {
console.log(error.message);
});
console.log('Validation link was sent to ' + email + '.');
}