fix(sveltekit-mailer): guard new Resend() against missing API key#2221
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(sveltekit-mailer): guard new Resend() against missing API key#2221posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sendAdminEmailin the SvelteKit CMSaasStarter template constructednew 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 missingPRIVATE_RESEND_API_KEYturned an optional, unconfigured email feature into a thrown error.This adds the same early-return guard that the sibling
sendTemplatedEmailfunction already uses — when the key is absent, the send is skipped gracefully instead of constructing the client. This mirrors the pattern already modeled in thereact-router/saas-templatemailer.Why
An error-tracking issue fired from a template deployment with no
RESEND_API_KEYset, surfacing the confusing "Missing API key. Pass it to the constructornew 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 othernew Resend()call in this file (sendTemplatedEmail) was already guarded.Created with PostHog Code from an inbox report.