import { POST } from "../../defs.js"; import type { structure } from "../../../apiStructure/sammoRootAPI.js"; import type { ExtractError, ExtractQuery, ExtractResponse } from "../../../apiStructure/defs.js"; import { StartSession } from "../../../ProcDecorator/StartSession.js"; import { delay } from "../../../util/delay.js"; import { declProcDecorators } from "../../../ProcDecorator/base.js"; import { type LoginCtx, loginCtxSessionKey } from "../../../ProcDecorator/ReqLogin.js"; import { z } from "zod"; type BaseAPI = typeof structure.Login.LoginByToken; type RType = ExtractResponse; type EType = ExtractError; type QType = ExtractQuery; const LoginByTokenReq = z.object({ token_id: z.number(), hashedToken: z.string(), }) satisfies z.ZodType export const LoginByToken = POST(LoginByTokenReq)(declProcDecorators( StartSession, )) (async (query, ctx) => { query.hashedToken; ctx.session.clear(); await delay(1); //무언가 로그인 //TODO: DB는 어디서 들고옴? const userID = 1; const userName = "test"; const userLevel = 1; const nextToken: [number, string] = [1, "1234567890"]; const loginCtx: LoginCtx = { userID, userName, userLevel, allowServerAction: new Set(), loginDate: new Date(), } ctx.session.setItem(loginCtxSessionKey, loginCtx); //throw new Error("Method not implemented."); return { result: true, nextToken, } });