shellphone.app/mailers/forgot-password-mailer.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-07-31 14:33:18 +00:00
/* TODO - You need to add a mailer integration in `integrations/` and import here.
*
* The integration file can be very simple. Instantiate the email client
* and then export it. That way you can import here and anywhere else
* and use it straight away.
*/
import previewEmail from "preview-email";
2021-07-31 14:33:18 +00:00
type ResetPasswordMailer = {
to: string;
token: string;
};
2021-07-31 14:33:18 +00:00
export function forgotPasswordMailer({ to, token }: ResetPasswordMailer) {
// In production, set APP_ORIGIN to your production server origin
const origin = process.env.APP_ORIGIN || process.env.BLITZ_DEV_SERVER_ORIGIN;
const resetUrl = `${origin}/reset-password?token=${token}`;
2021-07-31 14:33:18 +00:00
const msg = {
from: "TODO@example.com",
to,
subject: "Your Password Reset Instructions",
html: `
<h1>Reset Your Password</h1>
<h3>NOTE: You must set up a production email integration in mailers/forgotPasswordMailer.ts</h3>
<a href="${resetUrl}">
Click here to set a new password
</a>
`,
};
2021-07-31 14:33:18 +00:00
return {
async send() {
if (process.env.NODE_ENV === "production") {
// TODO - send the production email, like this:
// await postmark.sendEmail(msg)
2021-08-01 14:03:49 +00:00
throw new Error("No production email implementation in mailers/forgotPasswordMailer");
2021-07-31 14:33:18 +00:00
} else {
// Preview email in the browser
await previewEmail(msg);
2021-07-31 14:33:18 +00:00
}
},
};
2021-07-31 14:33:18 +00:00
}