Fix req.body with JSON.parse()

This commit is contained in:
aronmal 2023-02-13 23:21:38 +01:00
parent 15296f9163
commit da9337a50b
Signed by: aronmal
GPG key ID: 816B7707426FC612
3 changed files with 6 additions and 5 deletions

View file

@ -2,7 +2,7 @@ import { NextApiRequest } from "next"
async function getTokenFromBody<T>(payload: T & { req: NextApiRequest }) {
const { req } = payload
const token: string = req.body.token
const token: string = JSON.parse(req.body).token
// Checking for cookie presens, because it is necessary
if (!token) {

View file

@ -17,14 +17,15 @@ export default async function login(
req: NextApiRequest,
res: NextApiResponse<any>
) {
const { username, password } = req.body
return preCheck({
const { username, password } = JSON.parse(req.body)
const payload = {
req,
res,
username,
password,
newTokenType: "REFRESH" as Token["type"],
})
}
return preCheck(payload)
.then(getPlayerByNameDB)
.then(checkPasswordIsValid)
.then(createTokenDB)

View file

@ -13,7 +13,7 @@ export default async function register(
req: NextApiRequest,
res: NextApiResponse<any>
) {
const { username, password } = req.body
const { username, password } = JSON.parse(req.body)
return createPlayerDB({ req, res, username, password })
.then(registerResponse<Data>)
.then(sendResponse<Data>)