diff --git a/.env.example b/.env.example index ce5f17913124ad997e6af938e3ac9a0e5bc6a56d..f3afcc4b0abf91b564fb6abbf1126507d060a191 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,2 @@ REACT_APP_API_URL=http://stackspin_proxy:8081/api/v1 -REACT_APP_HYDRA_PUBLIC_URL=https://sso.init.stackspin.net +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 29cc3c5c6849c1a5562b74ef3e4bab4c0fc09b60..97a24eda56729ac74454a0b75d12385be3c0d293 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'; @@ -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 }, @@ -26,8 +28,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 +50,14 @@ const Header: React.FC<HeaderProps> = () => { const navigationItems = filterNavigationByDashboardRole(isAdmin); - const signOutUrl = `${HYDRA_URL}/oauth2/sessions/logout`; + 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 HYDRA_LOGOUT_URL; + } + return `https://${hostname.replace(/^dashboard/, 'sso')}/oauth2/sessions/logout`; + }, []); return ( <>