Skip to content

Commit

Permalink
Support multiple roles in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
luketn committed Aug 19, 2018
1 parent 71eb5b9 commit 63662c1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions frontend/src/auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ export default class Auth {
}

setProfile(error, profile) {
const userRole = profile[this.metadataKeyUserRole][0];
localStorage.setItem(KEY_USER_ROLE, (userRole || "").trim().toLowerCase());
const userRoles = profile[this.metadataKeyUserRole];
localStorage.setItem(KEY_USER_ROLE, (userRoles || [""]));

if (userRole === "facilitator") {
const firstUserRole = userRoles[0];
if (firstUserRole === "facilitator") {
history.replace("/facilitator");
} else if (userRole === "driver") {
} else if (firstUserRole === "driver") {
history.replace("/driver");
} else {
history.replace("/");
Expand Down Expand Up @@ -106,17 +107,17 @@ export default class Auth {
}

hasFacilitatorPriviledge() {
const userRole = localStorage.getItem(KEY_USER_ROLE);
return userRole === 'facilitator' || this.hasAdminPriviledge();
const userRoles = localStorage.getItem(KEY_USER_ROLE);
return userRoles.indexOf('facilitator') > -1 || this.hasAdminPriviledge();
}

hasDriverPriviledge() {
const userRole = localStorage.getItem(KEY_USER_ROLE);
return userRole === "driver" || this.hasAdminPriviledge();
const userRoles = localStorage.getItem(KEY_USER_ROLE);
return userRoles.indexOf("driver") > -1 || this.hasAdminPriviledge();
}

hasAdminPriviledge() {
const userRole = localStorage.getItem(KEY_USER_ROLE);
return userRole === "admin";
const userRoles = localStorage.getItem(KEY_USER_ROLE);
return userRoles.indexOf("admin") > -1;
}
}

0 comments on commit 63662c1

Please sign in to comment.