Is it good idea to store user auth token on $rootScope



I am planning to store user information like (user_id,auth_token,username) on $rootScope after user is authenticated but i am not sure if it is the right way to do it .
I am confused how to do this in a right way , attaching anything on $rootScope is bad but i am just attaching simple a user object i think it would be fine , but i am not sure if this is an elegant solution .

Can anyone pls guide me in the right way to do this


i don’t think it is a good idea to store the information there, might be best to just keep the information in the authentication service and provide a getter there to get the user object.

here is also a good article on authentication


After thinking for a while and using @aaronksaunders advice i have created CurrentUser service and put all user related information there .

Here is what i have done

User Logs in or Sign’s Up
After successful credentials , user token and other info is put in CurrentUser service which in turn puts data in localstorage.
And usual business thereafter

After user closea app and return later

Angular looks in localstorage for user data if found pulls it in CurretUser and proceeds the usual way if no data found Asks user to login .

Hope this is the right way to do it.


Can you share your findings?