Add hydra public url to environment

This commit is contained in:
Luka Radenovic 2022-06-09 11:10:28 +02:00
parent 165998cf1c
commit e5f06fc7b0
2 changed files with 7 additions and 20 deletions

2
.env.example Normal file
View file

@ -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

View file

@ -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<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 = () => {
@ -59,6 +42,8 @@ const Header: React.FC<HeaderProps> = () => {
const navigationItems = filterNavigationByDashboardRole(isAdmin);
const singOutUrl = `${HYDRA_URL}/oauth2/sessions/logout`;
return (
<>
<Disclosure as="nav" className="bg-white shadow relative z-10">
@ -139,7 +124,7 @@ const Header: React.FC<HeaderProps> = () => {
{({ active }) => (
<a
onClick={() => 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',