Files
the-biergarten-app/services/User/sendConfirmationEmail.ts
Aaron William Po 0d3785ad1a Add environment variable validation and parsing
Adds a validation schema for the application's environment variables using the Zod library. The parsed environment variables are then exported as constants that can be imported throughout the application, replacing the direct use of process.env.
2023-04-07 11:37:30 -04:00

27 lines
917 B
TypeScript

import { generateConfirmationToken } from '@/config/jwt';
import sendEmail from '@/config/sparkpost/sendEmail';
import Welcome from '@/emails/Welcome';
import { render } from '@react-email/render';
import { z } from 'zod';
import { BASE_URL } from '@/config/env';
import GetUserSchema from './schema/GetUserSchema';
type UserSchema = z.infer<typeof GetUserSchema>;
const sendConfirmationEmail = async ({ id, username, email }: UserSchema) => {
const confirmationToken = generateConfirmationToken({ id, username });
const subject = 'Confirm your email';
const name = username;
const url = `${BASE_URL}/api/users/confirm?token=${confirmationToken}`;
const address = email;
const html = render(Welcome({ name, url, subject })!);
const text = render(Welcome({ name, url, subject })!, { plainText: true });
await sendEmail({ address, subject, text, html });
};
export default sendConfirmationEmail;