auth0 / angular-jwt

Library to help you work with JWTs on AngularJS
MIT License
0 stars 1 forks source link

Fix unauthenticated redirection not working with ui-router 1.0 #155

Closed 4O4 closed 6 years ago

4O4 commented 7 years ago

Both unauthenticatedRedirector and unauthenticatedRedirectPath have no effect when using ui-router 1.0

This 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) and unauthenticatedRedirector 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 of onStart, so that the transition does not even begin when the client is unauthenticated.

dimonsizon commented 7 years ago

Hello. It is not working for me. I have ui-router 1.0

dimonsizon commented 7 years ago

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 } });

4O4 commented 7 years ago

@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

iudelsmann commented 6 years ago

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.

fostertheweb commented 6 years ago

Would love to see this merged. Anyway I could help make that happen?

FerreiraRaphael commented 6 years ago

This is working, please merge ...

4O4 commented 6 years ago

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.