MCPcopy Create free account
hub / github.com/ShipSecAI/studio / usePermissions

Function usePermissions

frontend/src/components/auth/usePermissions.ts:4–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3// Hook to check if current user has required permissions
4export function usePermissions() {
5 const { user, isAuthenticated } = useAuth();
6
7 const hasRole = (requiredRoles: string[]) => {
8 if (!isAuthenticated || !user) return false;
9
10 const userRole = user.organizationRole?.toUpperCase();
11 return requiredRoles.some((role) => userRole === role.toUpperCase() || role === '*');
12 };
13
14 const hasOrg = () => {
15 return isAuthenticated && user && !!user.organizationId;
16 };
17
18 const canAccess = (
19 options: {
20 requireAuth?: boolean;
21 requireOrg?: boolean;
22 roles?: string[];
23 } = {},
24 ) => {
25 const { requireAuth = true, requireOrg = false, roles = [] } = options;
26
27 if (requireAuth && !isAuthenticated) return false;
28 if (requireOrg && !hasOrg()) return false;
29 if (roles.length > 0 && !hasRole(roles)) return false;
30
31 return true;
32 };
33
34 return {
35 user,
36 isAuthenticated,
37 hasRole,
38 hasOrg,
39 canAccess,
40 };
41}

Callers

nothing calls this directly

Calls 1

useAuthFunction · 0.85

Tested by

no test coverage detected