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 { z } from "zod"; import { type LoginCtx, loginCtxSessionKey } from "../../../ProcDecorator/ReqLogin.js"; type BaseAPI = typeof structure.Login.LoginByID; type RType = ExtractResponse; type EType = ExtractError; type QType = ExtractQuery; const LoginByIDReq = z.object({ id: z.string(), password: z.string(), }) satisfies z.ZodType export const LoginByID = POST(LoginByIDReq)(declProcDecorators( StartSession, ))( async (query, ctx, req, res) => { const id = query.id; const password = query.password; //TODO: DB에서 뭔가 가져와야 함 await delay(1); if (Math.random() < 0.3) { return { result: false, reason: "로그인 실패", reqOTP: false, } } if (Math.random() < 0.5) { return { result: false, reason: "OTP 인증 필요", reqOTP: true, } } 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); return { result: true, nextToken, } });