docs: add instruction for t3 env to readme
This commit is contained in:
parent
5348d559b2
commit
dbb43c5d88
1 changed files with 23 additions and 1 deletions
24
README.md
24
README.md
|
|
@ -227,8 +227,30 @@ To use ChatGPT Code Review, add an `OPENAI_API_KEY` environment variable with an
|
|||
|
||||
[T3 Env](https://env.t3.gg/) is a library that provides environmental variables checking at build time, type validation and transforming. It ensures that your application is using the correct environment variables and their values are of the expected type. You’ll never again struggle with runtime errors caused by incorrect environment variable usage.
|
||||
|
||||
Config file is located at `env.mjs`. Simply set your client and server variables and import `env` from any file in your project.
|
||||
|
||||
```ts
|
||||
export const env = createEnv({
|
||||
server: {
|
||||
// Server variables
|
||||
SECRET_KEY: z.string(),
|
||||
},
|
||||
client: {
|
||||
// Client variables
|
||||
API_URL: z.string().url(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
// Assign runtime variables
|
||||
SECRET_KEY: process.env.SECRET_KEY,
|
||||
API_URL: process.env.NEXT_PUBLIC_API_URL,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
If the required environment variables are not set, you'll get an error message:
|
||||
|
||||
```sh
|
||||
❌ Invalid environment variables: { ANALYZE: [ 'Required' ] }
|
||||
❌ Invalid environment variables: { SECRET_KEY: [ 'Required' ] }
|
||||
```
|
||||
|
||||
## 🤝 Contribution
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue