diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..dad0d4f --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +REACT_APP_API_URL=http://127.0.0.1:5000/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 facd338..db86596 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -2,7 +2,6 @@ import React, { Fragment, useState } from 'react'; import { Disclosure, Menu, Transition } from '@headlessui/react'; import { MenuIcon, XIcon } from '@heroicons/react/outline'; import { useAuth } from 'src/services/auth'; -import { getDomainName } from 'src/common/util'; import Gravatar from 'react-gravatar'; import { Link, useLocation } from 'react-router-dom'; import clsx from 'clsx'; @@ -25,6 +24,8 @@ 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 {} @@ -32,24 +33,6 @@ const Header: React.FC = () => { const [currentUserModal, setCurrentUserModal] = useState(false); const { logOut, currentUser, isAdmin } = useAuth(); - const singOutUrl = () => { - const { hostname } = window.location; - const domain = getDomainName(window.location.hostname); - let url = `https://sso.${domain}/oauth2/sessions/logout`; - - // This is a fix so it can work with dashboard.init.stackspin.net - if (hostname.includes('init')) { - url = `https://sso.init.${domain}/oauth2/sessions/logout`; - } - - // This is a fix so it can work locally - if (hostname.includes('localhost')) { - url = 'https://sso.init.stackspin.net/oauth2/sessions/logout'; - } - - return url; - }; - const { pathname } = useLocation(); const currentUserModalOpen = () => { @@ -59,6 +42,8 @@ const Header: React.FC = () => { const navigationItems = filterNavigationByDashboardRole(isAdmin); + const singOutUrl = `${HYDRA_URL}/oauth2/sessions/logout`; + return ( <> @@ -139,7 +124,7 @@ const Header: React.FC = () => { {({ active }) => ( logOut()} - href={singOutUrl()} + href={singOutUrl} className={classNames( active ? 'bg-gray-100 cursor-pointer' : '', 'block px-4 py-2 text-sm text-gray-700 cursor-pointer',