
In this chapter, we will show you how to use Firebase Email/Password authentication.
To authenticate a user, we can use the createUserWithEmailAndPassword(email, password) method.
Let us consider the following example.
var email = "myemail@email.com";
var password = "mypassword";
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
console.log(error.code);
console.log(error.message);
});
We can check the Firebase dashboard and see that the user is created.
The Sign-in process is almost the same. We are using the signInWithEmailAndPassword(email, password) to sign in the user.
Let us consider the following example.
var email = "myemail@email.com";
var password = "mypassword";
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
console.log(error.code);
console.log(error.message);
});
And finally we can logout the user with the signOut() method.
Let us consider the following example.
firebase.auth().signOut().then(function() {
console.log("Logged out!")
}, function(error) {
console.log(error.code);
console.log(error.message);
});