From a5e4155a752fa090c7bc3751a803b4359453e56c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 25 Apr 2026 12:30:41 +0000 Subject: fix: frontend-backend connection bugs Agent-Logs-Url: https://github.com/bertyuan/next-blog/sessions/f86da32b-3af7-4393-8077-ce3435137221 Co-authored-by: bertyuan <189593334+bertyuan@users.noreply.github.com> --- src/lib/resend.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/resend.ts b/src/lib/resend.ts index 5ab7032..fb39186 100644 --- a/src/lib/resend.ts +++ b/src/lib/resend.ts @@ -1,9 +1,10 @@ +import { env } from '@/env'; import { baseUrl } from '@/lib/constants'; import { Resend, type UpdateContactOptions } from 'resend'; import NewsletterWelcomeEmail from '../../emails/newsletter-welcome'; -import type { getPosts } from './source'; +import type { BlogPost } from './payload-posts'; -const resend = new Resend(process.env.RESEND_API_KEY as string); +const resend = new Resend(env.RESEND_API_KEY); export async function updateContact({ email, @@ -53,18 +54,21 @@ export async function sendWelcomeEmail({ firstName, to, }: { - posts: ReturnType; + posts: BlogPost[]; firstName: string; to: string; }) { - const EMAIL_FROM = process.env.EMAIL_FROM as string; - if (!EMAIL_FROM) throw new Error('Missing EMAIL_FROM environment variable'); + const EMAIL_FROM = env.EMAIL_FROM; if (!firstName || !to) throw new Error('Missing required email fields'); const formattedPosts = posts.map((post) => ({ - ...post.data, - image: `${baseUrl}${post.data.image}`, - url: `${baseUrl}${post.url}`, + title: post.title, + description: post.description, + date: post.date, + tags: post.tags, + image: post.image ? new URL(post.image, baseUrl).href : undefined, + author: post.author, + url: new URL(post.url, baseUrl).href, })); const { data: res, error } = await resend.emails.send({ -- cgit v1.2.3