mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
fix(isa-app): Fixes Auth and TabID Errors on Startup
Refs: #5472, #5473
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -97,6 +97,7 @@ export class AuthService {
|
||||
this.#logger.info('AuthService initialized', () => ({ authenticated }));
|
||||
|
||||
this.#initialized.next(true);
|
||||
return authenticated;
|
||||
}
|
||||
|
||||
isAuthenticated() {
|
||||
|
||||
@@ -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';
|
||||
|
||||
31
libs/core/tabs/src/lib/has-tab-id.guard.ts
Normal file
31
libs/core/tabs/src/lib/has-tab-id.guard.ts
Normal 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');
|
||||
};
|
||||
Reference in New Issue
Block a user