Skip to content
Snippets Groups Projects
Commit 165998cf authored by Luka's avatar Luka
Browse files

Dashboard logout should trigger OAuth logout endpoint

parent d0edc5b2
No related branches found
No related tags found
1 merge request!32Dashboard logout should trigger OAuth logout endpoint
Pipeline #18696 passed with stages
in 2 minutes and 59 seconds
export function getDomainName(hostName: string) {
return hostName.substring(hostName.lastIndexOf('.', hostName.lastIndexOf('.') - 1) + 1);
}
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';
......@@ -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',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment