1
0
forked from noxious/server

code refractor

This commit is contained in:
2024-05-05 02:58:36 +02:00
parent 329c6597be
commit 56ae410fae
15 changed files with 225 additions and 148 deletions

View File

@ -1,35 +0,0 @@
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient();
export async function createUser(username: string, password: string): Promise<void> {
const salt = bcrypt.genSaltSync(10);
const hash = bcrypt.hashSync(password, salt);
await prisma.user.create({
data: {
username,
password: hash
}
});
}
export async function validateUser(username: string, password: string): Promise<boolean> {
const user = await prisma.user.findUnique({
where: {
username,
},
});
if (!user) return false;
return bcrypt.compareSync(password, user.password);
}
export async function getUser(username: string): Promise<any> {
return prisma.user.findUnique({
where: {
username,
},
});
}