summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>2026-04-25 12:30:41 +0000
committerBertrand Yuan <189593334+bertyuan@users.noreply.github.com>2026-04-27 14:50:52 +0800
commita5e4155a752fa090c7bc3751a803b4359453e56c (patch)
treecb722c79333c839884195f2697365e4df0dfe47e /src/lib
parent8b9c0139a93c8b9d41068e5271d0fc6917d34fab (diff)
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>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/resend.ts20
1 files changed, 12 insertions, 8 deletions
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<typeof getPosts>;
+ 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({