From 81c52aad7ab9dd03010997094f4230cf9c6cd9b7 Mon Sep 17 00:00:00 2001 From: garciafdezpatricia Date: Thu, 6 Jun 2024 14:10:44 +0200 Subject: [PATCH 1/4] fix: logout from both idp and app --- src/components/Header/Header.tsx | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 8448707..bbdd5bd 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -34,6 +34,31 @@ export default function Header({ }) { const { logout, session } = useContext(SessionContext); + const isUrl = (candidateUrl: string | URL) => { + try { + // If url is not URL-shaped, this will throw. + // eslint-disable-next-line no-new + new URL(candidateUrl); + return true; + } catch (_e) { + return false; + } + }; + + const handleLogout = async () => { + if ( + session.info.clientAppId !== undefined && + isUrl(session.info.clientAppId) + ) { + await logout({ + logoutType: "idp", + postLogoutUrl: new URL("/", window.location.href).toString(), + }); + } else { + await logout({ logoutType: "app" }); + } + }; + return (
@@ -44,12 +69,7 @@ export default function Header({