diff --git a/src/App.tsx b/src/App.tsx index 096c61dcb4..26742260bf 100644 --- a/src/App.tsx +++ b/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/src/slices/userInfoSlice.ts b/src/slices/userInfoSlice.ts index affe56ed39..f6084bb188 100644 --- a/src/slices/userInfoSlice.ts +++ b/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; });