Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get username in AngularJS controller? #1

Closed
michaeljoser opened this issue May 9, 2013 · 4 comments
Closed

How to get username in AngularJS controller? #1

michaeljoser opened this issue May 9, 2013 · 4 comments
Labels

Comments

@michaeljoser
Copy link

Hi i really like your auth code and I am using it as a template for my project.

I was wondering what would be the best way to keep the username accessible through my custom Controllers.

I saw that I can use $rootScope.userRole to get the userRole in my controllers but what would be an efficient way to keep username?

i tried a UserDetails factory that keeps the username. it worked until i do a refresh of the page (F5) then i loose the username value.

any idea please?

@fnakstad
Copy link
Owner

fnakstad commented May 9, 2013

Hi Michael,
I guess you could handle it in the same way as with the user role; just put the username in a cookie on the server-side when someone logs in, which you then can read into a $rootScope property when the Angular app has initialized. It's a pretty common use-case though, so I'll try to update my example with that functionality tomorrow. Thanks for the feedback!

@fnakstad
Copy link
Owner

I've updated the example to display username and indicate the role of the logged in user. You can check it out at: http://angular-client-side-auth.herokuapp.com/
I implemented it by setting a user cookie containing both username and role when a full page reload is requested. Furthermore, the login and register actions also return a user object of the same sort. Take a look at the code and example site, and let me know if something is unclear.

@michaeljoser
Copy link
Author

that's super nice and really fits my needs. Cheers :)

@fnakstad
Copy link
Owner

No problem :) Good luck with your project!

@ravivit9 ravivit9 mentioned this issue Jul 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants