auth logic (WIP), socket work (WIP)
This commit is contained in:
27
src/models/user.ts
Normal file
27
src/models/user.ts
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user