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.
|
|
|
|
*/
|
2021-07-31 15:57:43 +00:00
|
|
|
import previewEmail from "preview-email";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
type ResetPasswordMailer = {
|
2021-07-31 15:57:43 +00:00
|
|
|
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
|
2021-07-31 15:57:43 +00:00
|
|
|
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 15:57:43 +00:00
|
|
|
};
|
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
|
2021-07-31 15:57:43 +00:00
|
|
|
await previewEmail(msg);
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|
|
|
|
},
|
2021-07-31 15:57:43 +00:00
|
|
|
};
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|