From 89fe1efe8c1b8f9af0ace09cf10472a852e6aeb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Sch=C3=BCttl=C3=B6ffel?= Date: Fri, 17 May 2024 08:43:04 +0200 Subject: [PATCH 1/4] dont display ui when logged out --- app/src/slices/healthSlice.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/slices/healthSlice.ts b/app/src/slices/healthSlice.ts index 054f77535f..902db663fc 100644 --- a/app/src/slices/healthSlice.ts +++ b/app/src/slices/healthSlice.ts @@ -57,6 +57,12 @@ type FetchHealthStatusResponse = { // Fetch health status and transform it to further use export const fetchHealthStatus = createAsyncThunk('health/fetchHealthStatus', async () => { const res = await axios.get("/services/health.json"); + + // When http response is not 200, it is likely we are not logged in, so lets trigger a logout + if(res.status != 200) { + window.location.href = "/j_spring_security_logout"; + } + return res.data; }); From 74641726036f147c260abfb6084a31ca73277e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Sch=C3=BCttl=C3=B6ffel?= Date: Fri, 17 May 2024 09:03:51 +0200 Subject: [PATCH 2/4] redirect to login instead --- app/src/slices/healthSlice.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/slices/healthSlice.ts b/app/src/slices/healthSlice.ts index 902db663fc..ddf8205520 100644 --- a/app/src/slices/healthSlice.ts +++ b/app/src/slices/healthSlice.ts @@ -58,9 +58,9 @@ type FetchHealthStatusResponse = { export const fetchHealthStatus = createAsyncThunk('health/fetchHealthStatus', async () => { const res = await axios.get("/services/health.json"); - // When http response is not 200, it is likely we are not logged in, so lets trigger a logout + // When http response is not 200, it is likely we are not logged in, so lets redirect to login if(res.status != 200) { - window.location.href = "/j_spring_security_logout"; + window.location.href = "/login.html"; } return res.data; From d630f433a4c84ccbc54001a70bd7522ec5983420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Sch=C3=BCttl=C3=B6ffel?= Date: Wed, 22 May 2024 13:38:01 +0200 Subject: [PATCH 3/4] re-check me.json to verify if we are still logged in --- app/src/App.tsx | 6 ++++++ app/src/slices/userInfoSlice.ts | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/src/App.tsx b/app/src/App.tsx index 096c61dcb4..26742260bf 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -23,6 +23,12 @@ function App() { dispatch(fetchUserInfo()); // Load information about current opencast version on mount dispatch(fetchOcVersion()); + + // Add event listener for back button to check if we are still logged in + window.addEventListener("popstate", function(event) { + dispatch(fetchUserInfo()); + }); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/app/src/slices/userInfoSlice.ts b/app/src/slices/userInfoSlice.ts index 7732c93a80..5c11ae295e 100644 --- a/app/src/slices/userInfoSlice.ts +++ b/app/src/slices/userInfoSlice.ts @@ -85,6 +85,11 @@ export const fetchUserInfo = createAsyncThunk('UserInfo/fetchUserInfo', async (_ dispatch(addNotification({type: "error", key: "USER_NOT_SAVED"})); }); + // Redirect to login if not in ROLE_ADMIN_UI + if (!(res.roles.includes('ROLE_ADMIN') || res.roles.includes('ROLE_ADMIN_UI'))) { + window.location.href = "/login.html"; + } + return res; }); From d41dc0a32ad98bc0a07d64ed46a4183ceb90b153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Sch=C3=BCttl=C3=B6ffel?= Date: Wed, 22 May 2024 13:39:57 +0200 Subject: [PATCH 4/4] undo previous changes --- app/src/slices/healthSlice.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/slices/healthSlice.ts b/app/src/slices/healthSlice.ts index ddf8205520..054f77535f 100644 --- a/app/src/slices/healthSlice.ts +++ b/app/src/slices/healthSlice.ts @@ -57,12 +57,6 @@ type FetchHealthStatusResponse = { // Fetch health status and transform it to further use export const fetchHealthStatus = createAsyncThunk('health/fetchHealthStatus', async () => { const res = await axios.get("/services/health.json"); - - // When http response is not 200, it is likely we are not logged in, so lets redirect to login - if(res.status != 200) { - window.location.href = "/login.html"; - } - return res.data; });