Skip to content
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

Expose internal value for isServer #259

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/app/docs/customization/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const env = createEnv({
});
```

If you want to reuse above `isServer` check in multiple places, you can use the [`shared` section](./recipes#isserver).

## Treat empty strings as undefined

By default, T3 Env will feed the environment variables directly to the Zod validator. This means that if you have an empty string for a value that is supposed to be a number (e.g. `PORT=` in a ".env" file), Zod will flag
Expand Down
19 changes: 19 additions & 0 deletions docs/src/app/docs/recipes/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,22 @@ const config: StorybookConfig = {

export default config;
```

## isServer

Determining whether the code is running on the server or client is a common requirement.
You can use the `shared` section to define an environment variable that's accessible in both contexts:

```ts
export const env = createEnv({
shared: {
IS_SERVER: z.boolean().default(false),
},
runtimeEnv: {
IS_SERVER: typeof window === "undefined",
}
})
```

Make sure to read the [customization](./customization#tell-when-we're-in-a-server-context) docs to learn how to override the `isServer` value used by the library itself.