From 9de08ab233735035d4557bd908904c72501bfdda Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 2 Apr 2025 16:27:35 +0200 Subject: [PATCH] refactor: remove debug logs from auth components --- .../login-success/login-success.component.ts | 7 ------ frontend/src/app/service/auth.service.ts | 22 ++----------------- frontend/src/app/service/user.service.ts | 3 --- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/frontend/src/app/feature/login-success/login-success.component.ts b/frontend/src/app/feature/login-success/login-success.component.ts index 73428bf..eb873ea 100644 --- a/frontend/src/app/feature/login-success/login-success.component.ts +++ b/frontend/src/app/feature/login-success/login-success.component.ts @@ -17,30 +17,23 @@ export default class LoginSuccessComponent implements OnInit { private router: Router = inject(Router); async ngOnInit() { - console.log('Login success component initialized'); try { // Handle code flow without throwing errors const success = await this.oauthService.loadDiscoveryDocumentAndTryLogin(); - console.log('Manual login attempt result:', success); // If we have a valid access token, the user should be loaded in AuthService const user = this.authService.getUser(); - console.log('Login success user:', user); // Check if we're authenticated if (this.oauthService.hasValidAccessToken()) { - console.log('Valid access token found'); this.router.navigate(['/home']); } else { - console.log('No valid access token, waiting for auth service to complete'); // Wait a bit and check if we've been authenticated in the meantime setTimeout(() => { if (this.oauthService.hasValidAccessToken() || this.authService.getUser()) { - console.log('Now authenticated, navigating to home'); this.router.navigate(['/home']); } else { - console.log('Still not authenticated, redirecting to login page'); this.router.navigate(['/']); } }, 3000); diff --git a/frontend/src/app/service/auth.service.ts b/frontend/src/app/service/auth.service.ts index dfc3212..e9df1f7 100644 --- a/frontend/src/app/service/auth.service.ts +++ b/frontend/src/app/service/auth.service.ts @@ -27,7 +27,7 @@ export class AuthService { skipIssuerCheck: true, disableAtHashCheck: true, requireHttps: false, - showDebugInformation: true, // Enable for debugging + showDebugInformation: false, sessionChecksEnabled: false, }; @@ -38,7 +38,6 @@ export class AuthService { private user: User | null = null; constructor() { - console.log('Auth service initializing'); this.oauthService.configure(this.authConfig); this.setupEventHandling(); @@ -49,12 +48,10 @@ export class AuthService { window.location.search.includes('id_token='); if (hasAuthParams) { - console.log('Auth parameters detected in URL, processing code flow'); // We're in the OAuth callback this.processCodeFlow(); } else { // Normal app startup - console.log('Normal startup, checking for existing session'); this.checkExistingSession(); } } @@ -64,7 +61,6 @@ export class AuthService { this.oauthService .tryLogin({ onTokenReceived: (context) => { - console.log('Token received in code flow:', context); // Manually create a token_received event this.handleSuccessfulLogin(); }, @@ -79,7 +75,6 @@ export class AuthService { this.oauthService .loadDiscoveryDocumentAndTryLogin() .then((isLoggedIn) => { - console.log('Initial login attempt result:', isLoggedIn); if (isLoggedIn && !this.user) { this.handleSuccessfulLogin(); @@ -92,29 +87,21 @@ export class AuthService { private setupEventHandling() { this.oauthService.events.subscribe((event: OAuthEvent) => { - console.log('Auth event:', event); if (event.type === 'token_received') { this.handleSuccessfulLogin(); } else if (event.type === 'token_refresh_error' || event.type === 'token_expires') { - console.warn('Token issue detected:', event.type); } }); } private handleSuccessfulLogin() { - console.log('Access token received, loading user profile'); - console.log('Token valid:', this.oauthService.hasValidAccessToken()); - console.log('ID token valid:', this.oauthService.hasValidIdToken()); - console.log('Access token:', this.oauthService.getAccessToken()); // Extract claims from id token if available const claims = this.oauthService.getIdentityClaims(); - console.log('ID token claims:', claims); // If we have claims, use that as profile if (claims && (claims['sub'] || claims['email'])) { - console.log('Using ID token claims as profile'); this.processUserProfile(claims); return; } @@ -123,7 +110,7 @@ export class AuthService { try { from(this.oauthService.loadUserProfile()) .pipe( - tap((profile) => console.log('User profile loaded:', profile)), + tap((profile) => {}), catchError((error) => { console.error('Error loading user profile:', error); // If we can't load the profile but have a token, create a minimal profile @@ -143,7 +130,6 @@ export class AuthService { if (profile) { this.processUserProfile(profile); } else { - console.error('Could not load or create user profile'); this.router.navigate(['/']); } }); @@ -161,7 +147,6 @@ export class AuthService { private processUserProfile(profile: unknown) { this.fromUserProfile(profile as Record).subscribe({ next: (user) => { - console.log('User created/retrieved from backend:', user); this.user = user; this.router.navigate(['home']); }, @@ -178,13 +163,11 @@ export class AuthService { } login() { - console.log('Initiating login flow'); try { // First ensure discovery document is loaded this.oauthService .loadDiscoveryDocument() .then(() => { - console.log('Discovery document loaded, starting login flow'); this.oauthService.initLoginFlow(); }) .catch((err) => { @@ -204,7 +187,6 @@ export class AuthService { logout() { try { - console.log('Logging out'); this.user = null; // Prevent redirect to Authentik by doing a local logout only diff --git a/frontend/src/app/service/user.service.ts b/frontend/src/app/service/user.service.ts index 4a0d781..777a167 100644 --- a/frontend/src/app/service/user.service.ts +++ b/frontend/src/app/service/user.service.ts @@ -44,7 +44,6 @@ export class UserService { } 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 const info = profile['info'] as Record | undefined; @@ -56,11 +55,9 @@ export class UserService { (profile['name'] as string); if (!id || !username) { - console.error('Could not extract user ID or username from profile', profile); throw new Error('Invalid user profile data'); } - console.log(`Creating user with id: ${id}, username: ${username}`); return this.createUser(id, username); } }