From 45a9033299493eab228d87a0bba877f3b458ff24 Mon Sep 17 00:00:00 2001 From: Luka Radenovic Date: Wed, 13 Jul 2022 14:32:34 +0200 Subject: [PATCH 1/3] Fix logout link to be dynamically generated --- .env.example | 1 - src/components/Header/Header.tsx | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index ce5f179..c32c7c4 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1 @@ REACT_APP_API_URL=http://stackspin_proxy:8081/api/v1 -REACT_APP_HYDRA_PUBLIC_URL=https://sso.init.stackspin.net diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 29cc3c5..9428ec8 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -1,4 +1,4 @@ -import React, { Fragment, useState } from 'react'; +import React, { Fragment, useMemo, useState } from 'react'; import { Disclosure, Menu, Transition } from '@headlessui/react'; import { MenuIcon, XIcon } from '@heroicons/react/outline'; import { useAuth } from 'src/services/auth'; @@ -26,8 +26,6 @@ function filterNavigationByDashboardRole(isAdmin: boolean) { return navigation.filter((item) => !item.requiresAdmin); } -const HYDRA_URL = process.env.REACT_APP_HYDRA_PUBLIC_URL; - // eslint-disable-next-line @typescript-eslint/no-empty-interface interface HeaderProps {} @@ -50,7 +48,15 @@ const Header: React.FC = () => { const navigationItems = filterNavigationByDashboardRole(isAdmin); - const signOutUrl = `${HYDRA_URL}/oauth2/sessions/logout`; + // eslint-disable-next-line react-hooks/exhaustive-deps + const signOutUrl = useMemo(() => { + const { hostname } = window.location; + // If we are developing locally, we need to use the init cluster's public URL + if (hostname === 'localhost') { + return `https://sso.init.stackspin.net/oauth2/sessions/logout`; + } + return `https://sso.${hostname.replace('dashboard', '')}/oauth2/sessions/logout`; + }, []); return ( <> From 3f455aedd94296fb77c2ffe64dc8fe0ec15c14d9 Mon Sep 17 00:00:00 2001 From: Luka Radenovic Date: Wed, 13 Jul 2022 14:35:45 +0200 Subject: [PATCH 2/3] Cleanup singOutUrl --- src/components/Header/Header.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 9428ec8..7e67730 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -48,14 +48,13 @@ const Header: React.FC = () => { const navigationItems = filterNavigationByDashboardRole(isAdmin); - // eslint-disable-next-line react-hooks/exhaustive-deps const signOutUrl = useMemo(() => { const { hostname } = window.location; // If we are developing locally, we need to use the init cluster's public URL if (hostname === 'localhost') { return `https://sso.init.stackspin.net/oauth2/sessions/logout`; } - return `https://sso.${hostname.replace('dashboard', '')}/oauth2/sessions/logout`; + return `https://${hostname.replace('dashboard', 'sso')}/oauth2/sessions/logout`; }, []); return ( From d0b86c08092742e0cba01daa332cab165f6189fa Mon Sep 17 00:00:00 2001 From: Luka Radenovic Date: Wed, 13 Jul 2022 14:59:15 +0200 Subject: [PATCH 3/3] Add HYDRA_PUBLIC_URL env variable and fix replace of sing out url --- .env.example | 1 + src/components/Header/Header.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index c32c7c4..f3afcc4 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ REACT_APP_API_URL=http://stackspin_proxy:8081/api/v1 +REACT_APP_HYDRA_PUBLIC_URL=https://sso.init.stackspin.net \ No newline at end of file diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 7e67730..97a24ed 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -9,6 +9,8 @@ import _ from 'lodash'; import { UserModal } from '../UserModal'; +const HYDRA_LOGOUT_URL = `${process.env.REACT_APP_HYDRA_PUBLIC_URL}/oauth2/sessions/logout`; + const navigation = [ { name: 'Dashboard', to: '/dashboard', requiresAdmin: false }, { name: 'Users', to: '/users', requiresAdmin: true }, @@ -52,9 +54,9 @@ const Header: React.FC = () => { const { hostname } = window.location; // If we are developing locally, we need to use the init cluster's public URL if (hostname === 'localhost') { - return `https://sso.init.stackspin.net/oauth2/sessions/logout`; + return HYDRA_LOGOUT_URL; } - return `https://${hostname.replace('dashboard', 'sso')}/oauth2/sessions/logout`; + return `https://${hostname.replace(/^dashboard/, 'sso')}/oauth2/sessions/logout`; }, []); return (