mirror of
https://github.com/documenso/documenso.git
synced 2025-11-26 14:34:05 +10:00
Support runtime environment variables using server components. This will mean docker images can change env vars for runtime as required.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { createElement } from 'react';
|
|
|
|
import { mailer } from '@documenso/email/mailer';
|
|
import { render } from '@documenso/email/render';
|
|
import { ResetPasswordTemplate } from '@documenso/email/templates/reset-password';
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import { getRuntimeEnv } from '../../universal/runtime-env/get-runtime-env';
|
|
|
|
export interface SendResetPasswordOptions {
|
|
userId: number;
|
|
}
|
|
|
|
export const sendResetPassword = async ({ userId }: SendResetPasswordOptions) => {
|
|
const { NEXT_PUBLIC_WEBAPP_URL } = getRuntimeEnv();
|
|
|
|
const user = await prisma.user.findFirstOrThrow({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
});
|
|
|
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL || 'http://localhost:3000';
|
|
|
|
const template = createElement(ResetPasswordTemplate, {
|
|
assetBaseUrl,
|
|
userEmail: user.email,
|
|
userName: user.name || '',
|
|
});
|
|
|
|
return await mailer.sendMail({
|
|
to: {
|
|
address: user.email,
|
|
name: user.name || '',
|
|
},
|
|
from: {
|
|
name: process.env.NEXT_PRIVATE_SMTP_FROM_NAME || 'Documenso',
|
|
address: process.env.NEXT_PRIVATE_SMTP_FROM_ADDRESS || 'noreply@documenso.com',
|
|
},
|
|
subject: 'Password Reset Success!',
|
|
html: render(template),
|
|
text: render(template, { plainText: true }),
|
|
});
|
|
};
|