-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Why Auth.isLoggedInAsync() in app.js? #847
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
Comments
In addition to the unneeded overhead there is another issue: if a logged out user tries to go to a protected URL in the app directly (i.e. they type the URL into the browser or click a link they have) then It would be good if somehow there was a way to wait for the promise to resolve before completing the |
Did a quick search: looks like a pattern I've seen is to check if it's a protected route, and if so call |
@honkskillet - I just did this in .run(function ($rootScope, $state, Auth) {
var bypassAuthCheck = false;
// Redirect to login if route requires auth and you're not logged in
$rootScope.$on('$stateChangeStart', function (event, next, toParams) {
if (!next.authenticate || (next.authenticate && bypassAuthCheck)) {
return;
}
event.preventDefault();
Auth.isLoggedInAsync(function (loggedIn) {
if (!loggedIn) {
bypassAuthCheck = false;
$state.go('login');
} else {
bypassAuthCheck = true;
$state.go(next, toParams);
}
});
});
}); |
@ ramdog Thanks
This means that if the user decides he does not want to log in and hits the back button he will go back to the unauthorized page and get immediately redirected back to the login page. Unless the user spams the back button, he will end up in an ugly loop ping ponging between the unauthorized page and the login page. Instead, when redirecting to /login, this should be called
|
Just looking for a little clarification. What is the point of using 'Auth.isLoggedInAsync()' inside app.js?
By checking logged in status in an async manner, it allows a request for a route that the user may not be authenticated for to be send, incurring unneeded overhead, no? I'm sure I'm just in need of sleep, but what is the use for check logged in status asynchronously?
Thanks.
The text was updated successfully, but these errors were encountered: