32 lines
858 B
TypeScript
32 lines
858 B
TypeScript
import type { ServerActionType } from "../schema/gateway/User.js";
|
|
import type { SessionCtx } from "./StartSession.js";
|
|
import type { ProcDecorator } from "./base.js";
|
|
|
|
export type LoginCtx = {
|
|
userID: number;
|
|
userName: string;
|
|
userLevel: number;
|
|
allowServerAction?: Set<ServerActionType>;
|
|
loginDate: Date;
|
|
}
|
|
export const loginCtxSessionKey = 'loginCtx';
|
|
|
|
export function ReqLogin<Q extends SessionCtx>(): ProcDecorator<LoginCtx & Q, Q> {
|
|
return (ctx) => {
|
|
const loginCtx = ctx.session.getItem<LoginCtx>(loginCtxSessionKey);
|
|
if(!loginCtx){
|
|
return [{
|
|
result: false,
|
|
type: 'Required Login',
|
|
info: 'ReqLogin'
|
|
}, ctx];
|
|
}
|
|
|
|
return [{
|
|
result: true,
|
|
},{
|
|
...loginCtx,
|
|
...ctx,
|
|
}];
|
|
}
|
|
} |