diff --git a/src/App.js b/src/App.js index 4ed8c51..ea79637 100644 --- a/src/App.js +++ b/src/App.js @@ -9,6 +9,8 @@ import { CHALLENGES_PAGE, IS_MOBILE, POLICY_PRIVACY_PAGE, + LOGIN_REQUIRED_PAGES, + ROOT_URL, } from './utils/globals'; import KeyCloakService from './services/KeyCloakService'; import React from 'react'; @@ -28,6 +30,13 @@ const App = () => { const [confirmPopUpHandler, setConfirmPopUpHandler] = React.useState(null); React.useEffect(() => { + if (sessionStorage.getItem('logout') === 'yes') { + const pageName = window.location.pathname.split('/').at(-1); + if (LOGIN_REQUIRED_PAGES.includes(pageName)) { + window.location.replace(`${ROOT_URL}/challenges`); + } + } + if (sessionStorage.getItem('logged') !== 'yes') { if (KeyCloakService.isLoggedIn()) { sessionStorage.setItem('logged', 'yes'); diff --git a/src/services/KeyCloakService.js b/src/services/KeyCloakService.js index d394322..66d6619 100644 --- a/src/services/KeyCloakService.js +++ b/src/services/KeyCloakService.js @@ -30,12 +30,14 @@ const doLogin = () => { if (privacyPolicyAccept !== 'accept') { window.location = `${ROOT_URL}${POLICY_PRIVACY_PAGE}/login`; } else { + sessionStorage.setItem('logout', ''); _kc.login(); } }; const doLogout = () => { sessionStorage.clear(); + sessionStorage.setItem('logout', 'yes'); _kc.logout(); }; diff --git a/src/utils/globals.js b/src/utils/globals.js index 93f9d64..f839dd5 100644 --- a/src/utils/globals.js +++ b/src/utils/globals.js @@ -16,6 +16,8 @@ const POLICY_PRIVACY_PAGE = '/policy-privacy'; const CSI_LINK = 'https://csi.amu.edu.pl/'; const ROOT_URL = window.location.origin; +const LOGIN_REQUIRED_PAGES = ['myentries', 'submit', 'howto']; + const MINI_DESCRIPTION_RENDER = (description) => { if (description) { if (description.length <= MINI_DESCRIPTION_LENGTH) return description; @@ -83,6 +85,7 @@ export { CSI_LINK, POLICY_PRIVACY_PAGE, ROOT_URL, + LOGIN_REQUIRED_PAGES, MINI_DESCRIPTION_RENDER, RENDER_ICO, CALC_PAGES,