Skip to content

Commit

Permalink
Merge branch '397-dont-display-ui-when-loggedout' of schuettloeffel-e…
Browse files Browse the repository at this point in the history
…lsa/opencast-admin-interface into main

Pull request #401
Closes #397
  dont display ui when logged out
  • Loading branch information
gregorydlogan committed Jun 4, 2024
2 parents 1ff5bca + 3c97fa8 commit 776ba77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, []);

Expand Down
5 changes: 5 additions & 0 deletions src/slices/userInfoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down

0 comments on commit 776ba77

Please sign in to comment.