mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Implement confirm user functionality
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.
This commit is contained in:
@@ -11,10 +11,18 @@ import findUserByEmail from '@/services/User/findUserByEmail';
|
||||
import validateRequest from '@/config/nextConnect/middleware/validateRequest';
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
|
||||
import sendConfirmationEmail from '@/services/User/sendConfirmationEmail';
|
||||
|
||||
interface RegisterUserRequest extends NextApiRequest {
|
||||
body: z.infer<typeof CreateUserValidationSchema>;
|
||||
}
|
||||
|
||||
const { BASE_URL } = process.env;
|
||||
|
||||
if (!BASE_URL) {
|
||||
throw new ServerError('BASE_URL env variable is not set.', 500);
|
||||
}
|
||||
|
||||
const registerUser = async (req: RegisterUserRequest, res: NextApiResponse) => {
|
||||
const [usernameTaken, emailTaken] = await Promise.all([
|
||||
findUserByUsername(req.body.username),
|
||||
@@ -41,11 +49,14 @@ const registerUser = async (req: RegisterUserRequest, res: NextApiResponse) => {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
});
|
||||
res.status(201).json({
|
||||
message: 'User created successfully.',
|
||||
payload: user,
|
||||
statusCode: 201,
|
||||
|
||||
await sendConfirmationEmail(user);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
statusCode: 200,
|
||||
message: 'User registered successfully.',
|
||||
payload: user,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user