From c29f64b50b772411a6062b8215dbac5d06e799e6 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 14 Jun 2025 15:44:28 +0200 Subject: [PATCH] Enable debug logging for Keycloak authentication troubleshooting DEBUGGING: Add comprehensive console logging to track authentication flow ## Changes Made: ### 1. Configuration Updates (nuxt.config.ts) - Temporarily enabled keycloakDebug: true for production - Allows detailed logging to troubleshoot authentication issues ### 2. Enhanced Error Logging (composables/useKeycloak.ts) - Added [KEYCLOAK] prefixed console logs throughout login flow - Enhanced error reporting with message, stack, and name details - Added logging for initialization status and redirect URIs - TypeScript-safe error handling with instanceof checks ## Debug Information Now Available: - Keycloak initialization status - Login function execution tracking - Redirect URI generation details - Authentication state monitoring - Detailed error messages with stack traces This will help identify exactly where the authentication process is failing and provide actionable debugging information in the browser console. Ready for container rebuild and testing. --- composables/useKeycloak.ts | 28 +++++++++++++++++++++++++--- nuxt.config.ts | 4 ++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/composables/useKeycloak.ts b/composables/useKeycloak.ts index 37c8cb1..b49e099 100644 --- a/composables/useKeycloak.ts +++ b/composables/useKeycloak.ts @@ -124,23 +124,45 @@ export const useKeycloak = () => { } const login = async () => { + console.log('[KEYCLOAK] Login function called') + if (!keycloak.value) { + console.log('[KEYCLOAK] Keycloak not initialized, initializing now...') await initKeycloak() } if (keycloak.value) { try { const baseUrl = getBaseUrl() - logDebug('Starting login', { redirectUri: `${baseUrl}/dashboard` }) + console.log('[KEYCLOAK] Starting login', { + redirectUri: `${baseUrl}/dashboard`, + keycloakInitialized: !!keycloak.value, + keycloakAuthenticated: keycloak.value.authenticated + }) await keycloak.value.login({ redirectUri: `${baseUrl}/dashboard` }) + + console.log('[KEYCLOAK] Login method completed successfully') } catch (error) { - console.error('Login failed:', error) - logDebug('Login error', error) + console.error('[KEYCLOAK] Login failed:', error) + + if (error instanceof Error) { + console.error('[KEYCLOAK] Error details:', { + message: error.message, + stack: error.stack, + name: error.name + }) + } else { + console.error('[KEYCLOAK] Unknown error type:', error) + } + throw error } + } else { + console.error('[KEYCLOAK] No keycloak instance available for login') + throw new Error('Keycloak not available') } } diff --git a/nuxt.config.ts b/nuxt.config.ts index f0f3054..48e4aa6 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -135,8 +135,8 @@ export default defineNuxtConfig({ }, // Force HTTPS base URL for production baseUrl: "https://client.portnimara.dev", - // Enable debug mode for troubleshooting - keycloakDebug: process.env.NODE_ENV === 'development', + // Enable debug mode for troubleshooting (temporarily enabled for production) + keycloakDebug: true, }, }, vuetify: {