refactor: remove debug logs from auth components
Some checks failed
CI / Get Changed Files (pull_request) Successful in 7s
CI / prettier (pull_request) Failing after 23s
CI / eslint (pull_request) Failing after 28s
CI / test-build (pull_request) Successful in 1m16s
CI / Checkstyle Main (pull_request) Successful in 1m22s

This commit is contained in:
Jan K9f 2025-04-02 16:27:35 +02:00
parent 2e76446328
commit 9de08ab233
Signed by: jank
GPG key ID: B9F475106B20F144
3 changed files with 2 additions and 30 deletions

View file

@ -17,30 +17,23 @@ export default class LoginSuccessComponent implements OnInit {
private router: Router = inject(Router); private router: Router = inject(Router);
async ngOnInit() { async ngOnInit() {
console.log('Login success component initialized');
try { try {
// Handle code flow without throwing errors // Handle code flow without throwing errors
const success = await this.oauthService.loadDiscoveryDocumentAndTryLogin(); 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 // If we have a valid access token, the user should be loaded in AuthService
const user = this.authService.getUser(); const user = this.authService.getUser();
console.log('Login success user:', user);
// Check if we're authenticated // Check if we're authenticated
if (this.oauthService.hasValidAccessToken()) { if (this.oauthService.hasValidAccessToken()) {
console.log('Valid access token found');
this.router.navigate(['/home']); this.router.navigate(['/home']);
} else { } 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 // Wait a bit and check if we've been authenticated in the meantime
setTimeout(() => { setTimeout(() => {
if (this.oauthService.hasValidAccessToken() || this.authService.getUser()) { if (this.oauthService.hasValidAccessToken() || this.authService.getUser()) {
console.log('Now authenticated, navigating to home');
this.router.navigate(['/home']); this.router.navigate(['/home']);
} else { } else {
console.log('Still not authenticated, redirecting to login page');
this.router.navigate(['/']); this.router.navigate(['/']);
} }
}, 3000); }, 3000);

View file

@ -27,7 +27,7 @@ export class AuthService {
skipIssuerCheck: true, skipIssuerCheck: true,
disableAtHashCheck: true, disableAtHashCheck: true,
requireHttps: false, requireHttps: false,
showDebugInformation: true, // Enable for debugging showDebugInformation: false,
sessionChecksEnabled: false, sessionChecksEnabled: false,
}; };
@ -38,7 +38,6 @@ export class AuthService {
private user: User | null = null; private user: User | null = null;
constructor() { constructor() {
console.log('Auth service initializing');
this.oauthService.configure(this.authConfig); this.oauthService.configure(this.authConfig);
this.setupEventHandling(); this.setupEventHandling();
@ -49,12 +48,10 @@ export class AuthService {
window.location.search.includes('id_token='); window.location.search.includes('id_token=');
if (hasAuthParams) { if (hasAuthParams) {
console.log('Auth parameters detected in URL, processing code flow');
// We're in the OAuth callback // We're in the OAuth callback
this.processCodeFlow(); this.processCodeFlow();
} else { } else {
// Normal app startup // Normal app startup
console.log('Normal startup, checking for existing session');
this.checkExistingSession(); this.checkExistingSession();
} }
} }
@ -64,7 +61,6 @@ export class AuthService {
this.oauthService this.oauthService
.tryLogin({ .tryLogin({
onTokenReceived: (context) => { onTokenReceived: (context) => {
console.log('Token received in code flow:', context);
// Manually create a token_received event // Manually create a token_received event
this.handleSuccessfulLogin(); this.handleSuccessfulLogin();
}, },
@ -79,7 +75,6 @@ export class AuthService {
this.oauthService this.oauthService
.loadDiscoveryDocumentAndTryLogin() .loadDiscoveryDocumentAndTryLogin()
.then((isLoggedIn) => { .then((isLoggedIn) => {
console.log('Initial login attempt result:', isLoggedIn);
if (isLoggedIn && !this.user) { if (isLoggedIn && !this.user) {
this.handleSuccessfulLogin(); this.handleSuccessfulLogin();
@ -92,29 +87,21 @@ export class AuthService {
private setupEventHandling() { private setupEventHandling() {
this.oauthService.events.subscribe((event: OAuthEvent) => { this.oauthService.events.subscribe((event: OAuthEvent) => {
console.log('Auth event:', event);
if (event.type === 'token_received') { if (event.type === 'token_received') {
this.handleSuccessfulLogin(); this.handleSuccessfulLogin();
} else if (event.type === 'token_refresh_error' || event.type === 'token_expires') { } else if (event.type === 'token_refresh_error' || event.type === 'token_expires') {
console.warn('Token issue detected:', event.type);
} }
}); });
} }
private handleSuccessfulLogin() { 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 // Extract claims from id token if available
const claims = this.oauthService.getIdentityClaims(); const claims = this.oauthService.getIdentityClaims();
console.log('ID token claims:', claims);
// If we have claims, use that as profile // If we have claims, use that as profile
if (claims && (claims['sub'] || claims['email'])) { if (claims && (claims['sub'] || claims['email'])) {
console.log('Using ID token claims as profile');
this.processUserProfile(claims); this.processUserProfile(claims);
return; return;
} }
@ -123,7 +110,7 @@ export class AuthService {
try { try {
from(this.oauthService.loadUserProfile()) from(this.oauthService.loadUserProfile())
.pipe( .pipe(
tap((profile) => console.log('User profile loaded:', profile)), tap((profile) => {}),
catchError((error) => { catchError((error) => {
console.error('Error loading user profile:', error); console.error('Error loading user profile:', error);
// If we can't load the profile but have a token, create a minimal profile // If we can't load the profile but have a token, create a minimal profile
@ -143,7 +130,6 @@ export class AuthService {
if (profile) { if (profile) {
this.processUserProfile(profile); this.processUserProfile(profile);
} else { } else {
console.error('Could not load or create user profile');
this.router.navigate(['/']); this.router.navigate(['/']);
} }
}); });
@ -161,7 +147,6 @@ export class AuthService {
private processUserProfile(profile: unknown) { private processUserProfile(profile: unknown) {
this.fromUserProfile(profile as Record<string, unknown>).subscribe({ this.fromUserProfile(profile as Record<string, unknown>).subscribe({
next: (user) => { next: (user) => {
console.log('User created/retrieved from backend:', user);
this.user = user; this.user = user;
this.router.navigate(['home']); this.router.navigate(['home']);
}, },
@ -178,13 +163,11 @@ export class AuthService {
} }
login() { login() {
console.log('Initiating login flow');
try { try {
// First ensure discovery document is loaded // First ensure discovery document is loaded
this.oauthService this.oauthService
.loadDiscoveryDocument() .loadDiscoveryDocument()
.then(() => { .then(() => {
console.log('Discovery document loaded, starting login flow');
this.oauthService.initLoginFlow(); this.oauthService.initLoginFlow();
}) })
.catch((err) => { .catch((err) => {
@ -204,7 +187,6 @@ export class AuthService {
logout() { logout() {
try { try {
console.log('Logging out');
this.user = null; this.user = null;
// Prevent redirect to Authentik by doing a local logout only // Prevent redirect to Authentik by doing a local logout only

View file

@ -44,7 +44,6 @@ export class UserService {
} }
public getOrCreateUser(profile: Record<string, unknown>): Observable<User> { public getOrCreateUser(profile: Record<string, unknown>): Observable<User> {
console.log('Full authentik profile:', profile);
// Authentik format might differ from Keycloak // Authentik format might differ from Keycloak
// Check different possible locations for the ID and username // Check different possible locations for the ID and username
const info = profile['info'] as Record<string, unknown> | undefined; const info = profile['info'] as Record<string, unknown> | undefined;
@ -56,11 +55,9 @@ export class UserService {
(profile['name'] as string); (profile['name'] as string);
if (!id || !username) { if (!id || !username) {
console.error('Could not extract user ID or username from profile', profile);
throw new Error('Invalid user profile data'); throw new Error('Invalid user profile data');
} }
console.log(`Creating user with id: ${id}, username: ${username}`);
return this.createUser(id, username); return this.createUser(id, username);
} }
} }