Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 506
Nevin Avatar asked Dec 21 '25 20:12

Nevin


1 Answers

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;
        }
like image 63
qchap Avatar answered Dec 24 '25 11:12

qchap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!