Fix req.body with JSON.parse()
This commit is contained in:
parent
15296f9163
commit
da9337a50b
3 changed files with 6 additions and 5 deletions
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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>)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue