From e5f06fc7b069c55f9489b4c76771596f0537ed70 Mon Sep 17 00:00:00 2001
From: Luka Radenovic <luka@init.hr>
Date: Thu, 9 Jun 2022 11:10:28 +0200
Subject: [PATCH] Add hydra public url to environment

---
 .env.example                     |  2 ++
 src/components/Header/Header.tsx | 25 +++++--------------------
 2 files changed, 7 insertions(+), 20 deletions(-)
 create mode 100644 .env.example

diff --git a/.env.example b/.env.example
new file mode 100644
index 00000000..dad0d4f0
--- /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 facd338e..db865960 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<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',
-- 
GitLab