Update environment variables in resend module

This commit is contained in:
NeilClack
2026-07-17 12:42:42 -05:00
parent fd630ff714
commit c52474d69b
+9 -2
View File
@@ -11,7 +11,14 @@
import { Resend } from 'resend';
import { env } from '$env/dynamic/private';
export const resend = new Resend(env.RESEND_API_KEY);
let _resend: Resend;
function getResend(): Resend {
if (!_resend) {
_resend = new Resend(env.RESEND_API_KEY);
}
return _resend;
}
/**
* Send a transactional email using a Resend-hosted template.
@@ -38,7 +45,7 @@ export async function sendMail(options: {
}) {
const { to, subject, templateId, data } = options;
const result = await resend.emails.send({
const result = await getResend().emails.send({
from: env.EMAIL_FROM,
to: [to],
subject: subject ?? 'Template Email',