fix(auth): Use Angular Router for post-auth redirects

Replace window.location.href with Router.navigateByUrl() to ensure proper Angular navigation flow after authentication, maintaining state and avoiding full page reloads.
This commit is contained in:
Lorenz Hilpert
2025-11-12 15:58:38 +01:00
parent 0066e8baa1
commit b70f2798df

View File

@@ -1,11 +1,12 @@
import { coerceArray } from '@angular/cdk/coercion';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { Config } from '@core/config';
import { isNullOrUndefined } from '@utils/common';
import { AuthConfig, OAuthService } from 'angular-oauth2-oidc';
import { JwksValidationHandler } from 'angular-oauth2-oidc-jwks';
import { BehaviorSubject } from 'rxjs';
import { logger } from '@isa/core/logging';
import { Router } from '@angular/router';
/**
* Storage key for the URL to redirect to after login
@@ -17,6 +18,7 @@ const REDIRECT_URL_KEY = 'auth_redirect_url';
})
export class AuthService {
#logger = logger(() => ({ service: 'AuthService' }));
#router = inject(Router);
#initialized = new BehaviorSubject<boolean>(false);
get initialized$() {
@@ -48,7 +50,8 @@ export class AuthService {
this.#logger.debug('Redirecting after authentication', () => ({
redirectUrl,
}));
window.location.href = redirectUrl;
this.#router.navigateByUrl(redirectUrl);
}
}, 100);
}