-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroles.ts
More file actions
32 lines (27 loc) · 925 Bytes
/
roles.ts
File metadata and controls
32 lines (27 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export type AppRole = "admin" | "moderator" | "reader";
export function normalizeRole(role: string | null | undefined): AppRole {
if (role === "admin" || role === "moderator") {
return role;
}
return "reader";
}
export function isAdminRole(role: string | null | undefined): boolean {
return normalizeRole(role) === "admin";
}
export function isModeratorRole(role: string | null | undefined): boolean {
return normalizeRole(role) === "moderator";
}
export function isStaffRole(role: string | null | undefined): boolean {
const normalizedRole = normalizeRole(role);
return normalizedRole === "admin" || normalizedRole === "moderator";
}
export function getRoleLabel(role: string | null | undefined): string {
const normalizedRole = normalizeRole(role);
if (normalizedRole === "admin") {
return "Admin";
}
if (normalizedRole === "moderator") {
return "Moderator";
}
return "Reader";
}