1
0
forked from noxious/server

auth logic (WIP), socket work (WIP)

This commit is contained in:
2024-05-04 00:28:15 +02:00
parent a766fd8882
commit 0a51c72cc8
5 changed files with 121 additions and 532 deletions

27
src/models/user.ts Normal file
View File

@ -0,0 +1,27 @@
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);
}