auth0-angular
auth0-angular copied to clipboard
Ability to skip the error page redirect
If we have an AuthGuard
to prevent unauthenticated access to the protected routes,
then why are we redirecting the user to an error page if the auth0Client.checkSession
fails?
I'm not using auth guards in my app but still I get redirected to the home page /
if the session check fails.
Instead I want to keep the user on the same page and display a login view.
Describe the problem you'd like to have solved
I want the ability to stay on the same page even if the auth0Client.checkSession
fails.
Describe the ideal solution
The ideal solution would be to provide an option to disable redirect on session error.
Suggestion
A possible solution may be to add an option in the config to skip the error redirect
skipSessionErrorRedirect
which is something similar to the skipRedirectCallback
.
We can use the errors$
observable to take an action on session errors.
The default behaviour will remain the same until the skip error redirect flag is set to true
checkSession should be called on page load, you should be able to set errorPath
to the current URL to ensure we do not go to /
(the default) on an error (https://github.com/auth0/auth0-angular/blob/master/projects/auth0-angular/src/lib/auth.service.ts#L106).
That said, I think I agree that checkSession should not do anything when it fails. It is supposed to be silent.
Can you verify if the workaround above works for now? If it does, I would prefer fixing this in our next major version where we just avoid any action when checkSession fails.
It won't work for me because I don't want to redirect the user to the error page. I just intend to hide away some of the features on the same page and to prompt for optional authN with a dialogue. I'll be glad to make the contribution.
For now I wrote my own implementation of angular module from auth0-spa-js
.
The error redirect makes sense for general use cases but should be an optional feature.
👋 We have reworked Auth0-SPA-JS in such a way that calling checkSession
will never throw any exception anymore. This is available in beta and should soon be GA. Once we migrate our Angular SDK to use the latest version of SPA-JS, which will be a major bump inhere as well, this behavior should be resolved and checkSession
should never fail in our Angular SDK neither, so it shouldnt redirect anymore in that case.
Thanks, in the meanwhile I wrote my own wrapper for angular of the latest auth0-spa-js
. I'll keep an eye on your release. Do you accept contributions?