Fix Resend lazy init to avoid build-time API key error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-07 14:48:14 +05:00
parent 6975a9f97e
commit b40d518b74
+7 -5
View File
@@ -1,6 +1,8 @@
import { Resend } from "resend"; import { Resend } from "resend";
const resend = new Resend(process.env.RESEND_API_KEY); function getResend() {
return new Resend(process.env.RESEND_API_KEY);
}
const FROM = process.env.EMAIL_FROM ?? "noreply@mailsend.second-brain.ru"; const FROM = process.env.EMAIL_FROM ?? "noreply@mailsend.second-brain.ru";
const BASE_URL = process.env.BETTER_AUTH_URL ?? "https://school.second-brain.ru"; const BASE_URL = process.env.BETTER_AUTH_URL ?? "https://school.second-brain.ru";
@@ -36,7 +38,7 @@ function base(content: string) {
// ── Email senders ───────────────────────────────────────────────────────────── // ── Email senders ─────────────────────────────────────────────────────────────
export async function sendCourseAccessEmail(to: string, name: string, courseTitle: string) { export async function sendCourseAccessEmail(to: string, name: string, courseTitle: string) {
await resend.emails.send({ await getResend().emails.send({
from: FROM, from: FROM,
to, to,
subject: `Вам открыт доступ к курсу «${courseTitle}»`, subject: `Вам открыт доступ к курсу «${courseTitle}»`,
@@ -56,7 +58,7 @@ export async function sendHomeworkSubmittedEmail(
lessonTitle: string, lessonTitle: string,
submissionId: string submissionId: string
) { ) {
await resend.emails.send({ await getResend().emails.send({
from: FROM, from: FROM,
to, to,
subject: `Новая работа на проверку — ${lessonTitle}`, subject: `Новая работа на проверку — ${lessonTitle}`,
@@ -76,7 +78,7 @@ export async function sendFeedbackReceivedEmail(
feedbackText: string, feedbackText: string,
lessonUrl: string lessonUrl: string
) { ) {
await resend.emails.send({ await getResend().emails.send({
from: FROM, from: FROM,
to, to,
subject: `Получен фидбек по уроку «${lessonTitle}»`, subject: `Получен фидбек по уроку «${lessonTitle}»`,
@@ -93,7 +95,7 @@ export async function sendFeedbackReceivedEmail(
} }
export async function sendWelcomeEmail(to: string, name: string) { export async function sendWelcomeEmail(to: string, name: string) {
await resend.emails.send({ await getResend().emails.send({
from: FROM, from: FROM,
to, to,
subject: "Добро пожаловать в Second Brain", subject: "Добро пожаловать в Second Brain",