feat(frontend): added in checks for links inside the module
This commit is contained in:
@@ -1,17 +1,5 @@
|
||||
import {Modules} from "@/types/modules";
|
||||
|
||||
type User = {
|
||||
user_id: string;
|
||||
email: string;
|
||||
username: string;
|
||||
roles: Roles[];
|
||||
role: string;
|
||||
};
|
||||
|
||||
interface Roles {
|
||||
role: string;
|
||||
module_id: string;
|
||||
}
|
||||
import {User} from "@/types/users";
|
||||
|
||||
// user will need access to the module.
|
||||
// users role will determine there visual access
|
||||
@@ -23,3 +11,16 @@ export function hasAccess(user: User | null, moduleName: string | null, modules:
|
||||
|
||||
return user?.roles.find((role) => role.module_id === filteredModule[0].module_id) ? true : false;
|
||||
}
|
||||
|
||||
export function hasPageAccess(user: User | null, role: any, module_id: string): boolean {
|
||||
if (!user) return false;
|
||||
|
||||
// get only the module in the user profile
|
||||
const userRole = user?.roles.filter((role) => role.module_id === module_id);
|
||||
|
||||
if (role.includes(userRole[0].role)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user