2021-07-31 15:57:43 +00:00
|
|
|
import previewEmail from "preview-email";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
2021-10-26 21:34:21 +00:00
|
|
|
import { sendEmail } from "integrations/aws-ses";
|
2021-10-30 11:37:16 +00:00
|
|
|
import { render } from "./renderer";
|
2021-10-26 21:34:21 +00:00
|
|
|
|
2021-07-31 14:33:18 +00:00
|
|
|
type ResetPasswordMailer = {
|
2021-07-31 15:57:43 +00:00
|
|
|
to: string;
|
|
|
|
token: string;
|
2021-10-26 21:34:21 +00:00
|
|
|
userName: string;
|
2021-07-31 15:57:43 +00:00
|
|
|
};
|
2021-07-31 14:33:18 +00:00
|
|
|
|
2021-10-26 21:34:21 +00:00
|
|
|
export async function forgotPasswordMailer({ to, token, userName }: ResetPasswordMailer) {
|
2021-07-31 14:33:18 +00:00
|
|
|
// 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-10-30 11:37:16 +00:00
|
|
|
const html = await render("forgot-password", { action_url: resetUrl, name: userName });
|
2021-07-31 14:33:18 +00:00
|
|
|
const msg = {
|
2021-10-26 21:34:21 +00:00
|
|
|
from: "mokhtar@shellphone.app",
|
2021-07-31 14:33:18 +00:00
|
|
|
to,
|
2021-10-26 21:34:21 +00:00
|
|
|
subject: "Reset your password",
|
|
|
|
html,
|
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") {
|
2021-10-26 21:34:21 +00:00
|
|
|
await sendEmail({
|
|
|
|
recipients: [msg.to],
|
|
|
|
subject: msg.subject,
|
|
|
|
html: msg.html,
|
|
|
|
});
|
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
|
|
|
}
|