mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
begin extracting user controllers out of routes
This commit is contained in:
7
src/services/User/schema/TokenValidationSchema.ts
Normal file
7
src/services/User/schema/TokenValidationSchema.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import z from 'zod';
|
||||
|
||||
const TokenValidationSchema = z.object({
|
||||
token: z.string(),
|
||||
});
|
||||
|
||||
export default TokenValidationSchema;
|
||||
30
src/services/User/sendResetPasswordEmail.ts
Normal file
30
src/services/User/sendResetPasswordEmail.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { BASE_URL } from '@/config/env';
|
||||
import { generateResetPasswordToken } from '@/config/jwt';
|
||||
import sendEmail from '@/config/sparkpost/sendEmail';
|
||||
import ForgotEmail from '@/emails/ForgotEmail';
|
||||
import { User } from '@prisma/client';
|
||||
import type { ReactElement } from 'react';
|
||||
import { render } from '@react-email/render';
|
||||
|
||||
const sendResetPasswordEmail = async (user: User) => {
|
||||
const token = generateResetPasswordToken({ id: user.id, username: user.username });
|
||||
|
||||
const url = `${BASE_URL}/users/reset-password?token=${token}`;
|
||||
|
||||
const component = ForgotEmail({ name: user.username, url })! as ReactElement<
|
||||
unknown,
|
||||
string
|
||||
>;
|
||||
|
||||
const html = render(component);
|
||||
const text = render(component, { plainText: true });
|
||||
|
||||
await sendEmail({
|
||||
address: user.email,
|
||||
subject: 'Reset Password',
|
||||
html,
|
||||
text,
|
||||
});
|
||||
};
|
||||
|
||||
export default sendResetPasswordEmail;
|
||||
Reference in New Issue
Block a user