17 lines
493 B
TypeScript
17 lines
493 B
TypeScript
import type { Player } from "@prisma/client"
|
|
import bcrypt from "bcrypt"
|
|
import { rejectionErrors } from "../errors"
|
|
import sendError, { API } from "./sendError"
|
|
|
|
export default async function checkPasswordIsValid(
|
|
context: API,
|
|
player: Player,
|
|
password: string,
|
|
next: () => void
|
|
) {
|
|
// Validate for correct password
|
|
const result = await bcrypt.compare(password, player.passwordHash ?? "")
|
|
if (!result) return sendError(context, rejectionErrors.wrongPassword)
|
|
|
|
return next()
|
|
}
|