Merge branch 'fix/dynamic-logout' into 'main'

Fix logout link to be dynamically generated

See merge request stackspin/dashboard!46
This commit is contained in:
Maarten de Waard 2022-07-13 14:17:10 +00:00
commit f90180da43
2 changed files with 12 additions and 5 deletions

View file

@ -1,2 +1,2 @@
REACT_APP_API_URL=http://stackspin_proxy:8081/api/v1 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

View file

@ -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 { Disclosure, Menu, Transition } from '@headlessui/react';
import { MenuIcon, XIcon } from '@heroicons/react/outline'; import { MenuIcon, XIcon } from '@heroicons/react/outline';
import { useAuth } from 'src/services/auth'; import { useAuth } from 'src/services/auth';
@ -9,6 +9,8 @@ import _ from 'lodash';
import { UserModal } from '../UserModal'; import { UserModal } from '../UserModal';
const HYDRA_LOGOUT_URL = `${process.env.REACT_APP_HYDRA_PUBLIC_URL}/oauth2/sessions/logout`;
const navigation = [ const navigation = [
{ name: 'Dashboard', to: '/dashboard', requiresAdmin: false }, { name: 'Dashboard', to: '/dashboard', requiresAdmin: false },
{ name: 'Users', to: '/users', requiresAdmin: true }, { name: 'Users', to: '/users', requiresAdmin: true },
@ -26,8 +28,6 @@ function filterNavigationByDashboardRole(isAdmin: boolean) {
return navigation.filter((item) => !item.requiresAdmin); 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 // eslint-disable-next-line @typescript-eslint/no-empty-interface
interface HeaderProps {} interface HeaderProps {}
@ -50,7 +50,14 @@ const Header: React.FC<HeaderProps> = () => {
const navigationItems = filterNavigationByDashboardRole(isAdmin); 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 ( return (
<> <>