Add user and auth tests

This commit is contained in:
Aslan 2025-12-27 13:02:02 +01:00
parent 72d7b22891
commit 4bc3be87b4
15 changed files with 288 additions and 26 deletions

View file

@ -9,12 +9,20 @@ import { getJwtSecret } from "./helpers.js";
const registerUser = async (
registration: IUserRegistration,
): Promise<User | null> => {
const existingUser = await getDB().user.findUnique({
const existingUserUsername = await getDB().user.findUnique({
where: { username: registration.username },
});
if (existingUser) {
if (existingUserUsername) {
return null;
}
if (registration.email) {
const existingUserEmail = await getDB().user.findUnique({
where: { email: registration.email },
});
if (existingUserEmail) {
return null;
}
}
const passwordHash = await hashPassword(registration.password);