21 lines
536 B
JavaScript
21 lines
536 B
JavaScript
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
|
|
export function defineAbilitiesFor(user) {
|
|
const { can, cannot, build } = new AbilityBuilder(createMongoAbility);
|
|
|
|
if (user) {
|
|
can("access", "Dashboard");
|
|
cannot("access", "Login");
|
|
const parsedData = JSON.parse(user.value);
|
|
|
|
if (parsedData.roles && Object.values(parsedData.roles).includes("representation")) {
|
|
can("access", "Panel");
|
|
}
|
|
} else {
|
|
can("access", "Login");
|
|
cannot("access", "Dashboard");
|
|
}
|
|
|
|
return build();
|
|
}
|