Implementing user metadata retrieval
In many cases, having a user dashboard populated with the user's profile information is the way to go. This works well, especially if you have a Firebase-powered business application. The Firebase auth API offers an easy way to retrieve the currently authenticated user's metadata information, and in this recipe, we're going to see how we can do just that.
How to do it...
- In the authentication section within your code, exploit the
currentUser()
function, as shown in the following code block:
var user = firebase.auth().currentUser; var currentUser = {}; if (user != null) { currentUser.name = user.displayName; currentUser.email = user.email; currentUser.photoUrl = user.photoURL; currentUser.emailVerified = user.emailVerified; currentUser.uid = user.uid; }
With this, we can get the current user information and use it for our needs.
How it works...
In order to get the user metadata, the user needs to be...