Untitled

mail@pastecode.io avatar
unknown
typescript
a year ago
661 B
1
Indexable
Never
import { getStateStore } from '../global-state/Store';
function hasPermissions(permissions: string[], originalMethod: any) {
  return function (...args: any[]) {
    console.log(getStateStore());
    const userPermissions = getStateStore().appConfig.userPermissions;
    console.log('userPermissions', { userPermissions });
    const hasAllPermissions = permissions.every((permission) => userPermissions.includes(permission));
    if (!hasAllPermissions) {
      console.error(`User does not have permission to perform this action: ${permissions.join(', ')}`);
      return;
    }
    return originalMethod.apply(this, args);
  };
}

export { hasPermissions };