2025-06-15 15:36:48 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
2025-06-15 17:37:14 +02:00
|
|
|
console.log('[LOGOUT] Processing logout request')
|
|
|
|
|
|
2025-06-15 15:36:48 +02:00
|
|
|
try {
|
2025-06-15 17:37:14 +02:00
|
|
|
// Check for OIDC session
|
2025-06-15 17:03:42 +02:00
|
|
|
const oidcSession = getCookie(event, 'nuxt-oidc-auth')
|
2025-06-15 15:36:48 +02:00
|
|
|
|
2025-06-15 17:37:14 +02:00
|
|
|
// Clear OIDC session cookie
|
2025-06-15 17:03:42 +02:00
|
|
|
if (oidcSession) {
|
2025-06-15 17:37:14 +02:00
|
|
|
deleteCookie(event, 'nuxt-oidc-auth', {
|
|
|
|
|
domain: '.portnimara.dev',
|
|
|
|
|
path: '/'
|
|
|
|
|
})
|
2025-06-15 17:03:42 +02:00
|
|
|
console.log('[LOGOUT] OIDC session cleared')
|
|
|
|
|
}
|
2025-06-15 15:36:48 +02:00
|
|
|
|
2025-06-15 17:37:14 +02:00
|
|
|
// Always redirect to Keycloak logout to ensure complete logout
|
|
|
|
|
const logoutUrl = 'https://auth.portnimara.dev/realms/client-portal/protocol/openid-connect/logout?' +
|
|
|
|
|
new URLSearchParams({
|
|
|
|
|
redirect_uri: 'https://client.portnimara.dev/login'
|
|
|
|
|
}).toString()
|
|
|
|
|
|
|
|
|
|
console.log('[LOGOUT] Redirecting to Keycloak logout:', logoutUrl)
|
|
|
|
|
await sendRedirect(event, logoutUrl)
|
|
|
|
|
|
2025-06-15 15:36:48 +02:00
|
|
|
} catch (error) {
|
2025-06-15 17:03:42 +02:00
|
|
|
console.error('[LOGOUT] Logout error:', error)
|
2025-06-15 17:37:14 +02:00
|
|
|
|
|
|
|
|
// Fallback: clear cookies and redirect to login
|
|
|
|
|
try {
|
|
|
|
|
deleteCookie(event, 'nuxt-oidc-auth', {
|
|
|
|
|
domain: '.portnimara.dev',
|
|
|
|
|
path: '/'
|
|
|
|
|
})
|
|
|
|
|
} catch (cookieError) {
|
|
|
|
|
console.error('[LOGOUT] Cookie cleanup error:', cookieError)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await sendRedirect(event, '/login')
|
2025-06-15 15:36:48 +02:00
|
|
|
}
|
|
|
|
|
})
|