Initial commit: EduBox V2 platform
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user