35
Firebase Auth | Understanding The Auth
NOTE: This blog post assumes that you are at-least familiar with setting up firebase SDK
If you don't I'd recommend reading my blog on firebase firestore first
If you've built an application, you've probably had to deal with authentication and authorization
Contrary to Popular Belief
authentication !== authorization
Now as an Analogy
Authentication: Principal
Authorization: Security Guard
The Process of Verifying the Identity of a User
firebase.auth().createUserWithEmailAndPassword(
email,
password
);
NOTE: You Receive a Promise from any Function from Firebase
firebase.auth().signOut()
NOTE: Firebase removes the token stored on the client's localStorage (indexdb to be precise). It'll talk about it in detail in Authorization
firebase.auth().signInWithEmailAndPassword(
email,
password
)
// sends a pre-templated message to a specified email address
firebase.auth().sendEmailVerification(
email,
);
firebase.auth().sendPasswordResetEmail(
email
);
The Process of Controlling Access to an Asset
- It Updates A User Token > Very Similar To JWT but not restricted to web application
- It Stores the Token in the browser's indexDB (and not in the cookies) so it has a more controllable timeline
firebase.auth().onAuthStateChanged((user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
var uid = user.uid;
}
});
35