Closed 4O4 closed 6 years ago
Hello. It is not working for me. I have ui-router 1.0
jwtOptionsProvider.config({ tokenGetter: ['options', function(options) { if (options && options.url.substr(options.url.length - 5) == '.html') { return null; } return localStorage.getItem('id_token'); }], unauthenticatedRedirectPath: '/admin/login', whiteListedDomains: ['localhost', 'localhost/api'] });
I called it in run method authManager.redirectWhenUnauthenticated();
And my state .state('list', { url: '/admin/list', component: 'franchiseList', data: { requiresLogin: true } });
@dimonsizon Can you provide a working example on plunker or something? I'm unable to reproduce your problem
BTW I'm using this branch with ui-router 1.0.3 in production app since I submitted this PR and haven't encountered any problems
Tested and it did work. The original code makes no sense as it doesn't invoke the provided redirector function.
Can we please merge this and bump the version? I believe no backwards compatibility was made for ui-router < 1.0, but that's fine in my opinion.
Would love to see this merged. Anyway I could help make that happen?
This is working, please merge ...
I'm closing this PR because it's been 9 months and we still haven't received any response or feedback. This project is essentialy dead for me. I advise you guys to either use my fork as dependency or maintain your own.
Both
unauthenticatedRedirector
andunauthenticatedRedirectPath
have no effect when using ui-router 1.0This is caused by fix introduced in 02a8549 which aimed to resolve TransitionRejection error (see: #138 (comment))
Because of that, client is always being redirected to state defined in
loginPath
config option (which BTW doesn't appear to be used anywhere in the codebase or mentioned in documentation) andunauthenticatedRedirector
is never invoked.The solution is to abort current transition, wait until its processing is finished and then invoke redirector function. This can be achieved by either chaining off the transition promise or adding onError hook.
Invoking redirector function is delayed just in case there are some problems with using
$location
during transition, however it looks like it is currently working fine when using ui-router 1.0.3.TransitionRejection error still occurs, but this is correct behaviour and it does not cause any further implications for redirector function.
Additionally,
onBefore
transition hook should be used instead ofonStart
, so that the transition does not even begin when the client is unauthenticated.