From 79876f42b0aa76b1209a26d320a92fbf8bb65abf Mon Sep 17 00:00:00 2001 From: cv5ch <176032962+cv5ch@users.noreply.github.com> Date: Wed, 20 Aug 2025 12:04:05 +0200 Subject: [PATCH] Moved auto-login to app initializer to avoid having a token but no user in the auth component --- src/app/app.component.ts | 1 - src/app/core/_services/app-init.service.ts | 25 +++------------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index d4cf93d4..d3d63149 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -108,7 +108,6 @@ export class AppComponent implements OnInit, AfterViewInit { } ngOnInit(): void { - this.authService.autoLogin(); this.authService.isLogged.subscribe((status) => { this.isLogged = status; if (status) { diff --git a/src/app/core/_services/app-init.service.ts b/src/app/core/_services/app-init.service.ts index aaa6f1b1..d84da48a 100644 --- a/src/app/core/_services/app-init.service.ts +++ b/src/app/core/_services/app-init.service.ts @@ -1,34 +1,15 @@ -import { firstValueFrom } from 'rxjs'; -import { take } from 'rxjs/operators'; - import { Injectable } from '@angular/core'; import { AuthService } from '@services/access/auth.service'; -import { PermissionService } from '@services/permission/permission.service'; -import { AlertService } from '@services/shared/alert.service'; @Injectable({ providedIn: 'root' }) export class AppInitService { - constructor( - private permissionService: PermissionService, - private auth: AuthService, - private alertService: AlertService - ) {} + constructor(private auth: AuthService) {} /** * Call this on app start to ensure permissions are loaded, if user is already logged in */ - async initializeApp(): Promise { - try { - const isLoggedIn = this.auth.token !== 'notoken'; - - if (isLoggedIn) { - await firstValueFrom(this.permissionService.loadPermissions().pipe(take(1))); - } - } catch (err) { - console.error('Error during app initialization:', err); - this.alertService.showErrorMessage('Failed to initialize application permissions.'); - throw err; - } + initializeApp() { + this.auth.autoLogin(); } }