feat: ReqACL

This commit is contained in:
2024-03-09 14:48:08 +00:00
parent d87c177d50
commit bf8ad0a78c
+28
View File
@@ -0,0 +1,28 @@
import type { SessionCtx } from "@sammo/server_util";
import type { ProcDecorator } from "@strpc/express/proc_decorator";
import type { ServerActionType } from "@sammo/gateway_server/exports"
import { loginCtxSessionKey } from "./ReqLogin.js";
export type LoginCtx = {
userID: number;
userName: string;
userLevel: number;
allowServerAction?: Set<ServerActionType>;
loginDate: Date;
}
export function ReqACL<Q extends LoginCtx & SessionCtx>(action: ServerActionType): ProcDecorator<Q, Q> {
return (ctx) => {
if(ctx.allowServerAction?.has(action)){
return [{
result: true,
}, ctx];
}
return [{
result: false,
type: 'Required ACL',
info: `NotEnoughPermission: ${action}`
}, ctx];
}
}