From 0d3785ad1a282715d139d500a11a76adf3e0f980 Mon Sep 17 00:00:00 2001 From: Aaron William Po Date: Thu, 6 Apr 2023 23:38:03 -0400 Subject: [PATCH] Add environment variable validation and parsing Adds a validation schema for the application's environment variables using the Zod library. The parsed environment variables are then exported as constants that can be imported throughout the application, replacing the direct use of process.env. --- README.md | 6 +- .../BeerPostCommentsPaginationBar.tsx | 6 +- components/EditBeerPostForm.tsx | 2 +- components/ui/Navbar.tsx | 4 +- components/ui/alerts/ErrorAlert.tsx | 2 +- components/ui/forms/Button.tsx | 2 +- components/ui/forms/FormPageLayout.tsx | 2 +- config/auth/cookie.ts | 14 +- config/auth/session.ts | 7 +- config/cloudinary/index.ts | 10 +- config/env/index.ts | 136 ++++++++++++++++++ config/jwt/index.ts | 7 +- config/nextConnect/NextConnectOptions.ts | 3 +- config/sparkpost/client.ts | 7 +- config/sparkpost/sendEmail.ts | 7 +- package-lock.json | 5 +- package.json | 2 +- pages/beers/[id]/index.tsx | 2 +- prisma/DBClient.ts | 3 +- services/User/sendConfirmationEmail.ts | 8 +- tailwind.config.js | 5 +- 21 files changed, 171 insertions(+), 69 deletions(-) create mode 100644 config/env/index.ts diff --git a/README.md b/README.md index 251e364..61cb70e 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ SPARKPOST_SENDER_ADDRESS=" > .env - `CLOUDINARY_CLOUD_NAME`, `CLOUDINARY_KEY`, and `CLOUDINARY_SECRET` are the credentials for your Cloudinary account. - You can create a free account [here](https://cloudinary.com/users/register/free). - `CONFIRMATION_TOKEN_SECRET` is the secret used to sign the confirmation token used for email confirmation. - - You can generate a random string using the`openssl rand -hex 32` command. + - You can generate a random string using the`openssl rand -base64 127` command. - `SESSION_SECRET` is the secret used to sign the session cookie. - Use the same command as above to generate a random string. - `DATABASE_URL` is the URL of your CockroachDB database. @@ -118,10 +118,10 @@ npm run dev The Biergarten App is licensed under the GNU General Public License v3.0. This means that anyone is free to use, modify, and distribute the code as long as they also distribute their modifications under the same license. -I encourage anyone who uses this code for educational purposes to attribute the original author (i.e. me) and provide a link to the original repository. +I encourage anyone who uses this code for educational purposes to attribute me as the original author, and to provide a link to this repository. By contributing to this repository, you agree to license your contributions under the same license as the project. -If you have any questions or concerns about the license, please feel free to reach out to me.. +If you have any questions or concerns about the license, please feel free to submit an issue to this repository. I hope that this project will be useful to other developers and beer enthusiasts who are interested in learning about web development with Next.js, Prisma, CockroachDB, and other technologies. diff --git a/components/BeerById/BeerPostCommentsPaginationBar.tsx b/components/BeerById/BeerPostCommentsPaginationBar.tsx index 1925357..7bfa8bb 100644 --- a/components/BeerById/BeerPostCommentsPaginationBar.tsx +++ b/components/BeerById/BeerPostCommentsPaginationBar.tsx @@ -19,7 +19,7 @@ const BeerCommentsPaginationBar: FC = ({
= ({ > - + = ({ previousValues }) => { {isSubmitting ? 'Submitting...' : 'Submit'}
-