feat(frontend): added in checks for links inside the module

This commit is contained in:
2025-03-06 19:34:10 -06:00
parent 4195b9e8bc
commit c30a48c4b8
4 changed files with 126 additions and 23 deletions

View File

@@ -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;
}