New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: lazy validate env variables in the theme submit route #606
Conversation
✅ Deploy Preview for astro-www-2 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
| @@ -5,13 +5,15 @@ const schema = z.object({ | |||
| SUBMISSION_DISCORD_WEBHOOK_THREAD_ID: z.string(), | |||
| }) | |||
|
|
|||
| const result = schema.safeParse(import.meta.env) | |||
| if (!result.success) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of removing this wholesale maybe we move it behind a import.meta.env.CONTEXT === 'production' check? This would then only error for production builds (could maybe warn in other situations?)
Docs: https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah that's interesting! I try to avoid depending on Netlify's built-in variables to avoid issues when they don't exist in astro dev, but that actually makes sense in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out the fallback code gets a little wonky here checking import.meta.env.CONTEXT in addition to using safeParse to check for errors
Going to leave the easier fix here for now to unblock community PRs and open add it to the list of backlog tasks to revisit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change, I'm personally cool with this
1bf3199
to
8fa0628
Compare
This moves the check for
DISCORD_environment variables to a runtime check when the form is submittedWhy?
Netlify PR preview builds from community members won't include private environment variables, breaking the build immediately