diff --git a/src/controllers/api/loginController.ts b/src/controllers/api/loginController.ts index 51d3815f..52d4d6ac 100644 --- a/src/controllers/api/loginController.ts +++ b/src/controllers/api/loginController.ts @@ -1,20 +1,16 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import { RequestHandler } from "express"; import { config } from "@/src/services/configService"; import buildConfig from "@/static/data/buildConfig.json"; -import { toLoginRequest } from "@/src/helpers/loginHelpers"; import { Account } from "@/src/models/loginModel"; import { createAccount, isCorrectPassword, isNameTaken } from "@/src/services/loginService"; -import { IDatabaseAccountJson, ILoginResponse } from "@/src/types/loginTypes"; +import { IDatabaseAccountJson, ILoginRequest, ILoginResponse } from "@/src/types/loginTypes"; import { DTLS, groups, HUB, platformCDNs } from "@/static/fixed_responses/login_static"; import { logger } from "@/src/utils/logger"; export const loginController: RequestHandler = async (request, response) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument - const body = JSON.parse(request.body); // parse octet stream of json data to json object - const loginRequest = toLoginRequest(body); + const loginRequest = JSON.parse(String(request.body)) as ILoginRequest; // parse octet stream of json data to json object const account = await Account.findOne({ email: loginRequest.email }); //{ _id: 0, __v: 0 } const nonce = Math.round(Math.random() * Number.MAX_SAFE_INTEGER); diff --git a/src/helpers/loginHelpers.ts b/src/helpers/loginHelpers.ts deleted file mode 100644 index f9335822..00000000 --- a/src/helpers/loginHelpers.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ILoginRequest } from "@/src/types/loginTypes"; -import { parseEmail, parseNumber, parseString } from "./general"; - -const toLoginRequest = (loginRequest: unknown): ILoginRequest => { - if (!loginRequest || typeof loginRequest !== "object") { - throw new Error("incorrect or missing login request data"); - } - - // TODO: function that checks whether every field of interface is in object - if ( - "email" in loginRequest && - "password" in loginRequest && - "time" in loginRequest && - "s" in loginRequest && - "lang" in loginRequest && - "date" in loginRequest && - "ClientType" in loginRequest && - "PS" in loginRequest - ) { - return { - email: parseEmail(loginRequest.email), - password: parseString(loginRequest.password), - time: parseNumber(loginRequest.time), - s: parseString(loginRequest.s), - lang: parseString(loginRequest.lang), - date: parseNumber(loginRequest.date), - ClientType: parseString(loginRequest.ClientType), - PS: parseString(loginRequest.PS) - }; - } - - throw new Error("incorrect login request"); -}; - -export { toLoginRequest };