Implement login, add useUser hook

This commit is contained in:
Aaron William Po
2023-02-06 17:17:11 -05:00
parent 087a1a4513
commit 9a9d8bcb94
18 changed files with 336 additions and 43 deletions

View File

@@ -1,9 +1,8 @@
import findUserByUsername from '@/services/user/findUserByUsername';
import { hashPassword } from '@/config/auth/passwordFns';
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import ServerError from '@/config/util/ServerError';
import CreateUserValidationSchema from './schema/CreateUserValidationSchema';
import GetUserSchema from './schema/GetUserSchema';
const createNewUser = async ({
email,
@@ -13,17 +12,8 @@ const createNewUser = async ({
dateOfBirth,
username,
}: z.infer<typeof CreateUserValidationSchema>) => {
const userExists = await findUserByUsername(username);
if (userExists) {
throw new ServerError(
"Could not register a user with that username as it's already taken.",
409,
);
}
const hash = await hashPassword(password);
const user = DBClient.instance.user.create({
const user: z.infer<typeof GetUserSchema> = await DBClient.instance.user.create({
data: {
username,
email,