Files
2026-06-06 19:55:41 +00:00

17 lines
469 B
TypeScript

import { prisma } from "./prisma";
import bcrypt from "bcryptjs";
export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, 12);
}
export async function verifyPassword(password: string, hashed: string): Promise<boolean> {
return bcrypt.compare(password, hashed);
}
export function requireRole(user: { role: string }, ...allowed: string[]) {
if (!allowed.includes(user.role)) {
throw new Error("Forbidden");
}
}