64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
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<BaseAPI>;
|
|
type EType = ExtractError<BaseAPI>;
|
|
type QType = ExtractQuery<BaseAPI>;
|
|
const LoginByIDReq = z.object({
|
|
id: z.string(),
|
|
password: z.string(),
|
|
}) satisfies z.ZodType<QType>
|
|
|
|
export const LoginByID = POST<RType, EType, QType>(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,
|
|
}
|
|
}); |