fix(isa-app): Fixes Auth and TabID Errors on Startup

Refs: #5472, #5473
This commit is contained in:
Nino
2025-11-12 12:40:59 +01:00
parent 989294cc90
commit b827a6f0a0
5 changed files with 43 additions and 3 deletions

View File

@@ -29,7 +29,11 @@ import {
ActivateProcessIdWithConfigKeyGuard,
} from './guards/activate-process-id.guard';
import { MatomoRouteData } from 'ngx-matomo-client';
import { tabResolverFn, processResolverFn } from '@isa/core/tabs';
import {
tabResolverFn,
processResolverFn,
hasTabIdGuard,
} from '@isa/core/tabs';
import { provideScrollPositionRestoration } from '@isa/utils/scroll-position';
const routes: Routes = [
@@ -182,7 +186,7 @@ const routes: Routes = [
path: ':tabId',
component: MainComponent,
resolve: { process: processResolverFn, tab: tabResolverFn },
canActivate: [IsAuthenticatedGuard],
canActivate: [IsAuthenticatedGuard, hasTabIdGuard],
children: [
{
path: 'reward',

View File

@@ -131,7 +131,10 @@ export function _appInitializerFactory(config: Config, injector: Injector) {
const auth = injector.get(AuthService);
try {
await auth.init();
const authenticated = await auth.init();
if (!authenticated) {
throw new Error('User is not authenticated');
}
} catch {
statusElement.innerHTML = 'Authentifizierung wird durchgeführt...';
logger.info('Performing login');

View File

@@ -97,6 +97,7 @@ export class AuthService {
this.#logger.info('AuthService initialized', () => ({ authenticated }));
this.#initialized.next(true);
return authenticated;
}
isAuthenticated() {

View File

@@ -7,3 +7,4 @@ export * from './lib/tab-navigation.service';
export * from './lib/tab-navigation.constants';
export * from './lib/tab-config';
export * from './lib/helpers';
export * from './lib/has-tab-id.guard';

View File

@@ -0,0 +1,31 @@
import { inject } from '@angular/core';
import { CanActivateFn, Router } from '@angular/router';
import { logger } from '@isa/core/logging';
export const hasTabIdGuard: CanActivateFn = (route) => {
const router = inject(Router);
const log = logger(() => ({
context: 'hasTabIdGuard',
url: route.url.map((s) => s.path).join('/'),
params: JSON.stringify(route.params),
queryParams: JSON.stringify(route.queryParams),
}));
const tabId = route.params['tabId'];
const isValidTabId = tabId && !isNaN(parseInt(tabId)) && parseInt(tabId) > 0;
if (isValidTabId) {
log.debug('Valid tabId - allowing navigation', () => ({
tabId,
parsedValue: parseInt(tabId),
}));
return true;
}
log.warn('Invalid or missing tabId - redirecting to dashboard', () => ({
tabId,
isNaN: isNaN(parseInt(tabId)),
parsedValue: parseInt(tabId),
redirectTo: '/kunde/dashboard',
}));
return router.parseUrl('/kunde/dashboard');
};