pramudya-yb commited on
Commit ·
0118bca
1
Parent(s): be5b9d0
Log OTP and make email async
Browse files
packages/api/src/lib/email.ts
CHANGED
|
@@ -40,6 +40,10 @@ type SendOtpEmailProps = {
|
|
| 40 |
};
|
| 41 |
|
| 42 |
export async function sendOtpEmail({ to, otp, type }: SendOtpEmailProps) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if (!transporter) {
|
| 44 |
console.warn(`[email] Skipping OTP email to ${to} — SMTP not configured.`);
|
| 45 |
return;
|
|
@@ -48,7 +52,7 @@ export async function sendOtpEmail({ to, otp, type }: SendOtpEmailProps) {
|
|
| 48 |
const subject = subjects[type] || "Kode Verifikasi Pram";
|
| 49 |
const message = messages[type] || "Kode verifikasi Anda:";
|
| 50 |
|
| 51 |
-
|
| 52 |
from: env.SMTP_FROM,
|
| 53 |
to,
|
| 54 |
subject,
|
|
@@ -62,5 +66,7 @@ export async function sendOtpEmail({ to, otp, type }: SendOtpEmailProps) {
|
|
| 62 |
<p style="color: #6b7280; font-size: 14px;">Kode berlaku selama 5 menit. Jangan bagikan kode ini kepada siapapun.</p>
|
| 63 |
</div>
|
| 64 |
`,
|
|
|
|
|
|
|
| 65 |
});
|
| 66 |
}
|
|
|
|
| 40 |
};
|
| 41 |
|
| 42 |
export async function sendOtpEmail({ to, otp, type }: SendOtpEmailProps) {
|
| 43 |
+
console.log(`\n======================================================`);
|
| 44 |
+
console.log(`[BYPASS EMAIL] Kode OTP untuk ${to} adalah: ${otp}`);
|
| 45 |
+
console.log(`======================================================\n`);
|
| 46 |
+
|
| 47 |
if (!transporter) {
|
| 48 |
console.warn(`[email] Skipping OTP email to ${to} — SMTP not configured.`);
|
| 49 |
return;
|
|
|
|
| 52 |
const subject = subjects[type] || "Kode Verifikasi Pram";
|
| 53 |
const message = messages[type] || "Kode verifikasi Anda:";
|
| 54 |
|
| 55 |
+
transporter.sendMail({
|
| 56 |
from: env.SMTP_FROM,
|
| 57 |
to,
|
| 58 |
subject,
|
|
|
|
| 66 |
<p style="color: #6b7280; font-size: 14px;">Kode berlaku selama 5 menit. Jangan bagikan kode ini kepada siapapun.</p>
|
| 67 |
</div>
|
| 68 |
`,
|
| 69 |
+
}).catch((err) => {
|
| 70 |
+
console.error("[email] Error sending email (background):", err.message);
|
| 71 |
});
|
| 72 |
}
|