-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Auth promises and callbacks #456
Comments
With the release of angular 1.3.0 (still beta atm), $q receives some notable upgrades that would allow us to simplify the process even more. |
After more investigation, I think that resolves wouldn't (at this time) be suited for authentication in routes. However is still feel that returning promises from the Examples: _Auth.getCurrentUser_
_Auth.isLoggedIn_
_Auth.isAdmin_
Still allows for use as route resolves, and synchronous code by not passing any arguments. Just some 'opinions'... |
That looks good. Much cleaner. |
@DaftMonk you can checkout this branch if you'd like to see my changes. |
Changes: - getCurrentUser, isLoggedIn, and isAdmin are now sync if no arg and async with an arg - Use Error first callback signature where applicable - Remove unused arguments from Auth service - Remove isLoggedInAsync - Switch use of isLoggedInAsync to isLoggedIn - Add/Improve comments - Fix client/app/account(auth)/settings/settings.controller(js).js Breaking Changes: - Callbacks that return Errors, use 'Error first' signature Closes angular-fullstack#456
Hi, alert ( Auth.getCurrentUser().name ); Unfortunatly sometimes retrieving the user (when refreshing page) takes too much time --> undefined Workaround for me : User.get().$promise.then( function(user) {
alert ( user.name );
} I would prefer accessing currentUser through Auth service (but perhaps I'm just wrong). Note : I am just trying to enhance my user "settings" page Thanks in advance |
@sparqueur check out #465. In |
Ho, sorry. Think I was a little tired... |
@sparqueur no problem. Hope that helps you out 😄 |
Changes: - getCurrentUser, isLoggedIn, and isAdmin are now sync if no arg and async with an arg - Use Error first callback signature where applicable - Remove unused arguments from Auth service - Remove isLoggedInAsync - Switch use of isLoggedInAsync to isLoggedIn - Add/Improve comments - Fix client/app/account(auth)/settings/settings.controller(js).js Breaking Changes: - Callbacks that return Errors, use 'Error first' signature Closes #456
Closed by #465 |
@sparqueur thanks a lot, you saved my day! |
Looking over
client/components/auth/auth.service
it seems that it would be beneficial for us to use a signature for the methods that would allow for synchronous and async callback/promises.I would propose:
Its not terribly complicated and I feel provides maximum usability. Such as, all current calls to the auth methods would be maintained sync, we could remove methods such as isLoggedInAsync, and also we could use the promises they return in resolves for routes which could seriously improve the routing authentication.
I'd also like to point out the use of the 2nd argument
safe
, I've used it to allow us to receive promises that only resolve and not reject. This could be useful in a route resolve as well, being that if a promise is rejected then$routeChangeError
or$stateChangeError
is fired and we may not always want that.Another advantage would be that you could chain the promises with finer grained control, dictating whether or not a promise resolves into another (even on error) or is rejected and the chain canceled.
The text was updated successfully, but these errors were encountered: