v3: added a roles/permissions system, added user management tab on user profile
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 42s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 42s
This commit is contained in:
@@ -39,11 +39,19 @@ export interface Dump {
|
||||
* Authentication
|
||||
*/
|
||||
|
||||
export type Role = "user" | "moderator" | "admin";
|
||||
|
||||
export const ROLES: readonly Role[] = ["user", "moderator", "admin"];
|
||||
|
||||
export function isRole(value: unknown): value is Role {
|
||||
return typeof value === "string" && (ROLES as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
username: string;
|
||||
passwordHash: string;
|
||||
isAdmin: boolean;
|
||||
role: Role;
|
||||
createdAt: Date;
|
||||
updatedAt?: Date;
|
||||
avatarMime?: string;
|
||||
@@ -67,7 +75,7 @@ export interface RegisterUserRequest {
|
||||
export interface UpdateUserRequest {
|
||||
username?: string;
|
||||
password?: string;
|
||||
isAdmin?: boolean;
|
||||
role?: Role;
|
||||
description?: string | null;
|
||||
email?: string;
|
||||
}
|
||||
@@ -128,7 +136,7 @@ export function isUpdateUserRequest(obj: unknown): obj is UpdateUserRequest {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ("isAdmin" in o && typeof o.isAdmin !== "boolean") return false;
|
||||
if ("role" in o && !isRole(o.role)) return false;
|
||||
if (
|
||||
"description" in o && typeof o.description !== "string" &&
|
||||
o.description !== null
|
||||
@@ -152,7 +160,7 @@ export interface AuthResponse {
|
||||
export interface AuthPayload {
|
||||
userId: string;
|
||||
username: string;
|
||||
isAdmin: boolean;
|
||||
role: Role;
|
||||
exp: number;
|
||||
}
|
||||
|
||||
@@ -161,7 +169,7 @@ export function isAuthPayload(obj: unknown): obj is AuthPayload {
|
||||
typeof obj === "object" &&
|
||||
"userId" in obj && typeof obj.userId === "string" &&
|
||||
"username" in obj && typeof obj.username === "string" &&
|
||||
"isAdmin" in obj && typeof obj.isAdmin === "boolean" &&
|
||||
"role" in obj && isRole(obj.role) &&
|
||||
"exp" in obj && typeof obj.exp === "number";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user