Skip to content

fix(sveltekit-mailer): guard new Resend() against missing API key#2221

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/guard-resend-missing-key
Draft

fix(sveltekit-mailer): guard new Resend() against missing API key#2221
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/guard-resend-missing-key

Conversation

@posthog

@posthog posthog Bot commented Jun 30, 2026

Copy link
Copy Markdown

Summary

sendAdminEmail in the SvelteKit CMSaasStarter template constructed new Resend(env.PRIVATE_RESEND_API_KEY) without first checking the key was set. The Resend SDK throws at construction time when handed an empty/undefined key, so a deployment missing PRIVATE_RESEND_API_KEY turned an optional, unconfigured email feature into a thrown error.

This adds the same early-return guard that the sibling sendTemplatedEmail function already uses — when the key is absent, the send is skipped gracefully instead of constructing the client. This mirrors the pattern already modeled in the react-router/saas-template mailer.

Why

An error-tracking issue fired from a template deployment with no RESEND_API_KEY set, surfacing the confusing "Missing API key. Pass it to the constructor new Resend(\"re_123\")" exception. The fix makes any template app shipped without the env var fail gracefully rather than throw.

Note: the literal emitting app isn't in this repo (none of our Next.js templates import Resend) — this addresses the matching unguarded-constructor pattern in the SvelteKit template's sendAdminEmail. The other new Resend() call in this file (sendTemplatedEmail) was already guarded.


Created with PostHog Code from an inbox report.

sendAdminEmail constructed `new Resend(env.PRIVATE_RESEND_API_KEY)`
without first checking the key was set. When PRIVATE_RESEND_API_KEY is
absent, the Resend SDK throws at construction time, turning a missing
optional config into an error.

Add the same early-return guard that sendTemplatedEmail already uses, so
the admin email is skipped gracefully when email isn't configured.

Generated-By: PostHog Code
Task-Id: 9ce4855b-4902-42ed-8c1d-650d7eaeb516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants