api 구조 변경
This commit is contained in:
@@ -5,34 +5,42 @@ import { StartSession } from "../ProcDecorator/StartSession.js";
|
||||
import { IsNumber, IsString } from "class-validator";
|
||||
import { delay } from "../../util/delay.js";
|
||||
import { declProcDecorators } from "../ProcDecorator/base.js";
|
||||
import { LoginCtx, loginCtxSessionKey } from "../ProcDecorator/ReqLogin.js";
|
||||
import { z } from "zod";
|
||||
type BaseAPI = typeof structure.Login.LoginByToken;
|
||||
type RType = ExtractResponse<BaseAPI>;
|
||||
type EType = ExtractError<BaseAPI>;
|
||||
type QType = ExtractQuery<BaseAPI>;
|
||||
|
||||
class ArgValidator implements QType {
|
||||
@IsNumber()
|
||||
token_id!: number;
|
||||
@IsString()
|
||||
hashedToken!: string;
|
||||
}
|
||||
const LoginByTokenReq = z.object({
|
||||
token_id: z.number(),
|
||||
hashedToken: z.string(),
|
||||
}) satisfies z.ZodType<QType>
|
||||
|
||||
export const LoginByToken = POST<RType, EType, QType>
|
||||
(ArgValidator)
|
||||
(declProcDecorators([
|
||||
StartSession,
|
||||
] as const))
|
||||
export const LoginByToken = POST<RType, EType, QType>(LoginByTokenReq)(declProcDecorators(
|
||||
StartSession,
|
||||
))
|
||||
(async (query, ctx) => {
|
||||
query.hashedToken;
|
||||
ctx.clearSession();
|
||||
ctx.session.clear();
|
||||
|
||||
await delay(1);
|
||||
//무언가 로그인
|
||||
//TODO: DB는 어디서 들고옴?
|
||||
|
||||
const userID = 1;
|
||||
const userName = "test";
|
||||
const userLevel = 1;
|
||||
const nextToken: [number, string] = [1, "1234567890"];
|
||||
await ctx.setValue("userID", userID);
|
||||
const loginCtx: LoginCtx = {
|
||||
userID,
|
||||
userName,
|
||||
userLevel,
|
||||
allowServerAction: {},
|
||||
loginDate: new Date(),
|
||||
}
|
||||
|
||||
ctx.session.setItem(loginCtxSessionKey, loginCtx);
|
||||
|
||||
|
||||
//throw new Error("Method not implemented.");
|
||||
|
||||
Reference in New Issue
Block a user