Skip to content
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

[Question]: How to build a PartialRoutesGuard without auto-login #1963

Open
Ghostbird opened this issue Jun 12, 2024 · 0 comments
Open

[Question]: How to build a PartialRoutesGuard without auto-login #1963

Ghostbird opened this issue Jun 12, 2024 · 0 comments
Labels

Comments

@Ghostbird
Copy link

Ghostbird commented Jun 12, 2024

What Version of the library are you using?
18.0.0

Question

How can I make a custom guard, that works like the auto-login guard, except for the auto-login part. Instead I want to redirect the users to the app's internal login page. This is because we offer multiple different identity providers that the user can choose from.

I tried this documentation example but that doesn't work. I checked the library code, and oidcSecurityService.isAuthenticated$ is backed by private readonly authenticatedInternal$ = new BehaviorSubject<AuthenticatedResult>(DEFAULT_AUTHRESULT); from auth-state.service.ts. Where DEFAULT_AUTHRESULT.isAuthenticated is false.

The documentation for the property states:

Emits each time an authorization event occurs.

But that is clearly not true, as it always initially emits false.

Now you can see my problem. Once I get redirected back to my app, oidcSecurityService.isAuthenticated$.pipe(take(1)) always emits false exactly once, and therefore the route guard immediately concludes that you are not authenticated. That the AppComponent is still running checkAuth in the background, and will soon update the authentication state to say that you are authenticated is of no consequence.

Would it be possible to either:

  • Export more of the internals of the library? So that I can implement my own alternative to AutoLoginPartialRoutesGuard. Currently that's not possible, because the AutoLoginService, AuthStateService, and LoginService are not exported as part of this library's public API.
  • Make an extensible / configurable PartialRoutesGuard that makes the part that performs auto-login configurable?

I can probably workaround the route guard issue by putting a delay in my CallbackComponent before it routes. However,‌ I really like that the AutoLoginPartialRoutesGuard saves the target route and redirects back to the target route if you're logged in. In my opinion that is not related to automatic login at all. And I really want that feature. But to make that I would have to rewrite a lot of library internals simply because they're inaccessible.

@Ghostbird Ghostbird changed the title [Question]: [Question]: How to build a PartialRoutesGuard without auto-login Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant