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

Should I expect $auth.user to be loaded when in my controller? #139

Closed
davidtlee opened this issue Apr 11, 2015 · 2 comments
Closed

Should I expect $auth.user to be loaded when in my controller? #139

davidtlee opened this issue Apr 11, 2015 · 2 comments

Comments

@davidtlee
Copy link

In my controller setup code, I sometimes need to access the user object (e.g. using $auth.user.id to send as a parameter to a backend API). On occasion, it seems like the user object isn't populating since the backend API call seems to be missing that parameter.

Is this expected behavior? If so, what's the right way to access the user object at the right time? I know that one option might be to add validateUser as a state resolve, but that blocks the transition until the promise is finished. I prefer to transition to the page immediately and have a "loading...." indicator rather than causing any delay. But then this means I need some way of waiting for the validateUser to finish inside my controller logic. Any advice? Thanks!

@booleanbetrayal
Copy link
Collaborator

As a general rule, I recommend the resolver strategy as it will be less problematic, but if you're looking to begin the transition immediately, you may wish to setup a watch expression on $rootScope.user which ng-token-auth sets upon successful validation / login. Either that, or listen to the auth:login-success and auth:validation-success events.

Hope this helps. Please let me know if you need to re-open this issue!

@davidtlee
Copy link
Author

Got it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants