Manage Users in Firebase

We previously discussed how to create, sign in, and sign out users. Now, let’s look at how to retrieve, manage, and update user profiles in Firebase.

Get the currently signed-in user

There are two ways of getting the signed-in user in our application—the onAuthStateChanged function and the currentUser property.

The onAuthStateChanged function

The onAuthStateChanged function sets an observer on the Firebase Auth object. It is the recommended way to get the current user. When we use an observer, we ensure that the Auth object is no longer in an intermediate state when getting the current user. This means that, at any given time, the function waits until the user’s authentication state has been resolved before it triggers, as we can see here:

Get hands-on with 1400+ tech skills courses.