-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: add environment variables validation #147
Conversation
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.
On my phone, but think you should add something to the tsconfig too in order to get the file validated with ts ☺
Hi there! Please remember to update the PR title so we get it on the changelog. feat: add environment variables validation Cheers! |
I've added |
Should I change it to something else? |
It's perfect now! Thanks Quick question, what happens when just "next-auth + trpc" or just "next-auth" is enabled? |
I am thinking of adding the boilerplate |
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.
I do really like this
The only problem with this as it stands, is that it would make the initial app fail to build because of the example .env not following this validation-schema. I just added a CI step that builds the default t3-app and this would fail if we do not include a better |
Also include one for just NextAuth.js |
3cbaf16
to
94805fe
Compare
I've moved schema to |
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.
I like this. Left some comments. As for the concern in my comment previously, would this prevent the app from building if the .env schema is not valid or is it just runtime?
EDIT: looks like the CI answered my question. Should we also include a .env that can be validated or what are your thoughts on this?
> [email protected] build /home/runner/work/create-t3-app/ci-test-app
[8](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:9)
> next build
[9](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:10)
[10](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:11)
❌ Invalid environment variables:
[11](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:12)
DATABASE_URL: Required
[12](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:13)
NEXTAUTH_SECRET: Required
[13](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:14)
NEXTAUTH_URL: Required
[14](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:15)
GITHUB_ID: Required
[15](https://github.com/t3-oss/create-t3-app/runs/7252027908?check_suite_focus=true#step:8:16)
GITHUB_SECRET: Required
Looks good! Update the branch and I'll merge |
Updated 👍 |
Thank you 🙏! |
Add runtime environment variables validation
In #140 @KATT suggested adding runtime environment variables validation using zod. Since
env.js
is imported insidenext.config.js
it can't ba a typescript file. There are two templates forenv.js
, one for just prismaenv-prisma.js
and another one for prisma + next-authenv-prisma-auth.js
Screenshots
💯