angularjs - How to get ensureLoggedIn working with routeProvider -
i'm working on node.js application, using angular.js, passport , connect-ensure-login.
only on refresh (f5), redirect in ensureloggedin seem work , login page, otherwise think routeprovider one-page app takes on normal click , localhost:3000/users still 500 error '/api/users'.
how can connect-ensure-login (ensureloggedin) working both direct path , click-through?
app.get('/users', ensureloggedin('/login'))
for apis, i'm using
app.get('/api/users', passport.authenticate('bearer'), ...
routeprovider snippet application:
.config(function($routeprovider, $locationprovider) { $routeprovider .when('/', { templateurl: 'views/home.html' }) ...
references:
you may want go solving issue making use of $httpprovider.interceptors
.
in case catch 500
error coming /api/users
(though better return 401
or 403
) , have interceptor kick in , take user /login
.
here's official doc:
http://docs.angularjs.org/api/ng/service/$http#interceptors
here's more specific example:
http://blog.thesparktree.com/post/75952317665/angularjs-interceptors-globally-handle-401-and-other
and here's similar answer.
Comments
Post a Comment