diff --git a/src/common/util/domain.ts b/src/common/util/domain.ts new file mode 100644 index 0000000000000000000000000000000000000000..7152af58692637d49ff223b93c95f4de008a581b --- /dev/null +++ b/src/common/util/domain.ts @@ -0,0 +1,3 @@ +export function getDomainName(hostName: string) { + return hostName.substring(hostName.lastIndexOf('.', hostName.lastIndexOf('.') - 1) + 1); +} diff --git a/src/common/util/index.ts b/src/common/util/index.ts index 40a831a5829fffe35f5518099852446f32d6d838..da954030ee1fb2ad4286e4bc6a3e3d02b2948c0d 100644 --- a/src/common/util/index.ts +++ b/src/common/util/index.ts @@ -1,2 +1,3 @@ -export { isTouched } from './is-touched'; -export { addParamsToLink } from './add-params-to-link'; +export * from './is-touched'; +export * from './add-params-to-link'; +export * from './domain'; diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index a58e2d82adfcb801fa24535dcc59e0da38e0d92e..facd338eaaffa081f1038c3e36a027521db52ebc 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -2,6 +2,7 @@ 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'; @@ -31,6 +32,24 @@ const Header: React.FC<HeaderProps> = () => { 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 = () => { @@ -120,6 +139,7 @@ const Header: React.FC<HeaderProps> = () => { {({ active }) => ( <a onClick={() => logOut()} + href={singOutUrl()} className={classNames( active ? 'bg-gray-100 cursor-pointer' : '', 'block px-4 py-2 text-sm text-gray-700 cursor-pointer',