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:
+7
-5
@@ -1,6 +1,8 @@
|
||||
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 BASE_URL = process.env.BETTER_AUTH_URL ?? "https://school.second-brain.ru";
|
||||
|
||||
@@ -36,7 +38,7 @@ function base(content: string) {
|
||||
// ── Email senders ─────────────────────────────────────────────────────────────
|
||||
|
||||
export async function sendCourseAccessEmail(to: string, name: string, courseTitle: string) {
|
||||
await resend.emails.send({
|
||||
await getResend().emails.send({
|
||||
from: FROM,
|
||||
to,
|
||||
subject: `Вам открыт доступ к курсу «${courseTitle}»`,
|
||||
@@ -56,7 +58,7 @@ export async function sendHomeworkSubmittedEmail(
|
||||
lessonTitle: string,
|
||||
submissionId: string
|
||||
) {
|
||||
await resend.emails.send({
|
||||
await getResend().emails.send({
|
||||
from: FROM,
|
||||
to,
|
||||
subject: `Новая работа на проверку — ${lessonTitle}`,
|
||||
@@ -76,7 +78,7 @@ export async function sendFeedbackReceivedEmail(
|
||||
feedbackText: string,
|
||||
lessonUrl: string
|
||||
) {
|
||||
await resend.emails.send({
|
||||
await getResend().emails.send({
|
||||
from: FROM,
|
||||
to,
|
||||
subject: `Получен фидбек по уроку «${lessonTitle}»`,
|
||||
@@ -93,7 +95,7 @@ export async function sendFeedbackReceivedEmail(
|
||||
}
|
||||
|
||||
export async function sendWelcomeEmail(to: string, name: string) {
|
||||
await resend.emails.send({
|
||||
await getResend().emails.send({
|
||||
from: FROM,
|
||||
to,
|
||||
subject: "Добро пожаловать в Second Brain",
|
||||
|
||||
Reference in New Issue
Block a user