mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
This commit adds the necessary functionality to confirm a user's account. It includes the addition of a new column in the user table to track whether an account is confirmed or not, and the implementation of JWT for confirmation tokens. This commit integrates the SparkPost API as well as React Email to send dynamic emails for whatever purpose. Upon user registration, a confirmation email will be sent to the user.
41 lines
934 B
TypeScript
41 lines
934 B
TypeScript
import { hashPassword } from '@/config/auth/passwordFns';
|
|
import DBClient from '@/prisma/DBClient';
|
|
import { z } from 'zod';
|
|
import CreateUserValidationSchema from './schema/CreateUserValidationSchema';
|
|
import GetUserSchema from './schema/GetUserSchema';
|
|
|
|
const createNewUser = async ({
|
|
email,
|
|
password,
|
|
firstName,
|
|
lastName,
|
|
dateOfBirth,
|
|
username,
|
|
}: z.infer<typeof CreateUserValidationSchema>) => {
|
|
const hash = await hashPassword(password);
|
|
const user: z.infer<typeof GetUserSchema> = await DBClient.instance.user.create({
|
|
data: {
|
|
username,
|
|
email,
|
|
hash,
|
|
firstName,
|
|
lastName,
|
|
dateOfBirth: new Date(dateOfBirth),
|
|
},
|
|
select: {
|
|
id: true,
|
|
username: true,
|
|
email: true,
|
|
firstName: true,
|
|
lastName: true,
|
|
dateOfBirth: true,
|
|
createdAt: true,
|
|
isAccountVerified: true,
|
|
},
|
|
});
|
|
|
|
return user;
|
|
};
|
|
|
|
export default createNewUser;
|