Skip to content

Commit

Permalink
check RBAC by github username rather than email
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish701 committed Nov 18, 2024
1 parent 5a6d986 commit 1080521
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/src/Testing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ function Testing() {

useEffect(() => {
const admins = import.meta.env.VITE_ADMINS?.split(',') || [];
const currentUserEmail = keycloak.tokenParsed?.email;
const currentUsername = keycloak.tokenParsed?.preferred_username;

// Check if the current user's email is in the restricted list
if (currentUserEmail && admins.includes(currentUserEmail)) {
if (currentUsername && admins.includes(currentUsername)) {
setIsAdmin(true);
}
}, []);
Expand Down
4 changes: 2 additions & 2 deletions app/src/keycloakProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function KeycloakProvider({ children }) {
keycloak
.init({ onLoad: 'login-required' })
.then((authenticated) => {
const userEmail = keycloak.tokenParsed?.email;
const username = keycloak.tokenParsed?.preferred_username;

const users = import.meta.env.VITE_USERS?.split(',') || [];

if (!userEmail || !users.includes(userEmail)) {
if (!username || !users.includes(username)) {
keycloak.logout();
return;
}
Expand Down

0 comments on commit 1080521

Please sign in to comment.