19 lines
538 B
TypeScript
19 lines
538 B
TypeScript
import { Player } from "@prisma/client"
|
|
import bcrypt from "bcrypt"
|
|
import errors from "../errors"
|
|
import sendError from "./sendError"
|
|
import { NextApiRequest, NextApiResponse } from "next"
|
|
|
|
export default async function checkPasswordIsValid(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse,
|
|
player: Player,
|
|
password: string,
|
|
next: () => void
|
|
) {
|
|
// Validate for correct password
|
|
const result = await bcrypt.compare(password, player.passwordHash)
|
|
if (!result) return sendError(req, res, errors.wrongPassword)
|
|
|
|
return next()
|
|
}
|