Reputation: 375
I'm trying to get the user.id
of a user after successful login using Angular/Firebase then assign it into a global variable. Is that possible ?
Upvotes: 3
Views: 1183
Reputation: 345
I think the best way is to build a service to manage your users. A service is a singleton so it's a proper way to store and manage these types of data.
You can build something like this:
//... code of your service ..
Var currentUser={};
function login()
{
// ... Code of you login function including you auth method ...
if (user && !user.isAnonymous) {
currentUser.userid = user.uid;
}
}
function getCurrentUser(){
return currentUser;
}
Upvotes: 3