Files
core_ng/server/ProcDecorator/ReqGatewayLogin.ts
T
2023-08-18 16:20:10 +00:00

33 lines
965 B
TypeScript

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,
}];
}
}