From d3b7e7d5e7e2e86eddf740cc64529dcefef07ec0 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 2 Apr 2025 16:15:31 +0200 Subject: [PATCH] refactor: improve type annotations in services and config --- frontend/src/app/app.config.ts | 4 +++- frontend/src/app/service/auth.service.ts | 6 +++--- frontend/src/app/service/user.service.ts | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/app.config.ts b/frontend/src/app/app.config.ts index 6528f15..db1a848 100644 --- a/frontend/src/app/app.config.ts +++ b/frontend/src/app/app.config.ts @@ -8,9 +8,10 @@ import { provideAnimationsAsync } from '@angular/platform-browser/animations/asy import { OAuthStorage, provideOAuthClient } from 'angular-oauth2-oidc'; import { httpInterceptor } from './shared/interceptor/http.interceptor'; +/* Example of a custom storage factory - not used in the current implementation function storageFactory() { return new (class implements OAuthStorage { - private data: { [key: string]: string } = {}; + private data: Record = {}; getItem(key: string): string | null { return this.data[key]; @@ -25,6 +26,7 @@ function storageFactory() { } })(); } +*/ export const appConfig: ApplicationConfig = { providers: [ diff --git a/frontend/src/app/service/auth.service.ts b/frontend/src/app/service/auth.service.ts index 8554dc6..aaf7c8d 100644 --- a/frontend/src/app/service/auth.service.ts +++ b/frontend/src/app/service/auth.service.ts @@ -109,7 +109,7 @@ export class AuthService { console.log('Access token:', this.oauthService.getAccessToken()); // Extract claims from id token if available - let claims = this.oauthService.getIdentityClaims(); + const claims = this.oauthService.getIdentityClaims(); console.log('ID token claims:', claims); // If we have claims, use that as profile @@ -128,7 +128,7 @@ export class AuthService { console.error('Error loading user profile:', error); // If we can't load the profile but have a token, create a minimal profile if (this.oauthService.hasValidAccessToken()) { - const token = this.oauthService.getAccessToken(); + this.oauthService.getAccessToken(); // Get token but don't use it directly // Create a basic profile from the token const minimalProfile = { sub: 'user-' + Math.random().toString(36).substring(2, 10), @@ -158,7 +158,7 @@ export class AuthService { } } - private processUserProfile(profile: any) { + private processUserProfile(profile: Record) { this.fromUserProfile(profile).subscribe({ next: (user) => { console.log('User created/retrieved from backend:', user); diff --git a/frontend/src/app/service/user.service.ts b/frontend/src/app/service/user.service.ts index 4bb37f6..aba8145 100644 --- a/frontend/src/app/service/user.service.ts +++ b/frontend/src/app/service/user.service.ts @@ -43,7 +43,7 @@ export class UserService { .pipe(tap((user) => this.currentUserSubject.next(user))); } - public getOrCreateUser(profile: any): Observable { + public getOrCreateUser(profile: Record): Observable { console.log('Full authentik profile:', profile); // Authentik format might differ from Keycloak // Check different possible locations for the ID and username