redirect to challenges page after logout

This commit is contained in:
Mateusz Tylka 2023-03-29 13:36:49 +02:00
parent 3ff0c6ea87
commit d88bb1d0ea
3 changed files with 14 additions and 0 deletions

View File

@ -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');

View File

@ -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();
};

View File

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