Files
core_ng/server/api/RootAPI/Login/LoginByToken.ts
T
2023-08-19 04:49:26 +00:00

51 lines
1.6 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 { type 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>;
const LoginByTokenReq = z.object({
token_id: z.number(),
hashedToken: z.string(),
}) satisfies z.ZodType<QType>
export const LoginByToken = POST<RType, EType, QType>(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,
}
});