feat(api): add auth guards
This commit is contained in:
1 parent
3a86676a12
commit
d4b790fd86
16 files changed
+592
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { CommunityRole } from '../global/database/schema';
|
||||
|
||||
export type Permission =
|
||||
| 'community:edit'
|
||||
| 'community:delete'
|
||||
| 'community:transfer'
|
||||
| 'user:role:manage'
|
||||
| 'match:create'
|
||||
| 'match:edit'
|
||||
| 'match:delete'
|
||||
| 'auction:manage';
|
||||
|
||||
type PermissionSet = readonly Permission[] | readonly ['*'];
|
||||
|
||||
export const ROLE_PERMISSIONS: Record<CommunityRole, PermissionSet> = {
|
||||
owner: ['*'] as const,
|
||||
admin: [
|
||||
'community:edit',
|
||||
'user:role:manage',
|
||||
'match:create',
|
||||
'match:edit',
|
||||
'match:delete',
|
||||
'auction:manage',
|
||||
] as const,
|
||||
member: [] as const,
|
||||
};
|
||||
|
||||
export function roleHasPermission(
|
||||
role: CommunityRole,
|
||||
permission: Permission,
|
||||
): boolean {
|
||||
const perms = ROLE_PERMISSIONS[role];
|
||||
if (perms.length === 1 && perms[0] === '*') return true;
|
||||
return (perms as readonly Permission[]).includes(permission);
|
||||
}
|
||||
Reference in new issue
Block a user