diff --git a/app/loggedout/page.tsx b/app/loggedout/page.tsx index f6b998b2..7377d617 100644 --- a/app/loggedout/page.tsx +++ b/app/loggedout/page.tsx @@ -1,11 +1,13 @@ "use client"; -import { useEffect, useState } from "react"; +import { useEffect, useState, useRef } from "react"; import { clearAuthCookies } from "@/lib/session"; import Link from "next/link"; export default function LoggedOut() { const [sessionStatus, setSessionStatus] = useState<'checking' | 'cleared' | 'error'>('checking'); + const iframeRef = useRef(null); + const forceLogout = new URLSearchParams(window.location.search).get('forceLogout') === 'true'; // Listen for any messages from iframes useEffect(() => { @@ -27,6 +29,18 @@ export default function LoggedOut() { // Additional browser storage clearing console.log('Performing complete browser storage cleanup'); + // Add a hidden iframe to directly call Keycloak logout endpoint + // This ensures the server-side Keycloak session is properly terminated + if (process.env.NEXT_PUBLIC_KEYCLOAK_ISSUER) { + console.log('Adding Keycloak logout iframe'); + const keycloakBaseUrl = process.env.NEXT_PUBLIC_KEYCLOAK_ISSUER; + const logoutEndpoint = `${keycloakBaseUrl}/protocol/openid-connect/logout`; + + if (iframeRef.current) { + iframeRef.current.src = logoutEndpoint; + } + } + // Try to get any user ID from localStorage or sessionStorage for server-side cleanup let userId = ''; try { @@ -124,6 +138,8 @@ export default function LoggedOut() { 'rc_token', 'rc_uid', 'Meteor.loginToken', + 'AUTH_SESSION_ID', + 'AUTH_SESSION_ID_LEGACY', ...chunkedCookies ]; @@ -136,6 +152,13 @@ export default function LoggedOut() { document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=.${rootDomain}; SameSite=None; Secure;`; } + // Additional paths that Keycloak might use + ['/auth', '/realms'].forEach(path => { + keycloakCookies.forEach(cookieName => { + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${window.location.hostname}; SameSite=None; Secure;`; + }); + }); + // Notify any parent windows/iframes try { if (window.parent && window.parent !== window) { @@ -165,6 +188,13 @@ export default function LoggedOut() { backgroundRepeat: 'no-repeat' }} > + {/* Hidden iframe for direct Keycloak logout */} +