gateway 구분중

This commit is contained in:
2023-08-18 16:20:10 +00:00
parent 87c239610a
commit 635d7f167d
8 changed files with 89 additions and 11 deletions
+33
View File
@@ -0,0 +1,33 @@
import type { GatewayActionType, ServerActionType } from "../schema/gateway/User.js";
import type { SessionCtx } from "./StartSession.js";
import type { ProcDecorator } from "./base.js";
export type GatewayLoginCtx = {
userID: number;
userName: string;
userLevel: number;
allowServerAction: Map<string, Set<ServerActionType>>;
allowGatewayAction: Set<GatewayActionType>;
loginDate: Date;
}
export const loginCtxSessionKey = 'loginCtx';
export function ReqGatewayLogin<Q extends SessionCtx>(): ProcDecorator<GatewayLoginCtx & Q, Q> {
return (ctx) => {
const loginCtx = ctx.session.getItem<GatewayLoginCtx>(loginCtxSessionKey);
if(!loginCtx){
return [{
result: false,
type: 'Required Login',
info: 'ReqLogin'
}, ctx];
}
return [{
result: true,
},{
...loginCtx,
...ctx,
}];
}
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { ServerActionType } from "../schema/gateway/User.js";
import type { SessionCtx } from "./StartSession.js";
import type { ProcDecorator } from "./base.js";
@@ -5,7 +6,7 @@ export type LoginCtx = {
userID: number;
userName: string;
userLevel: number;
allowServerAction: Record<string, number>;
allowServerAction: Set<ServerActionType>;
loginDate: Date;
}
export const loginCtxSessionKey = 'loginCtx';