Nevin
Nevin

Reputation: 375

Setting the Firebase user.uid to a global variable

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

Answers (1)

qchap
qchap

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

Related Questions