Skip to content

Commit

Permalink
Expose internal value for isServer
Browse files Browse the repository at this point in the history
Fixes #258

Expose the internal value for `isServer` for reuse across the app.

* **packages/core/src/index.ts**
  - Add `isServer` property to the `CreateEnv` return type.
  - Update the `createEnv` function to include `isServer` in the proxy handler.
* **examples/astro/src/t3-env.ts**
  - Import `isServer` value from the `env` object.
* **examples/nextjs/app/env.ts**
  - Import `isServer` value from the `env` object.
* **examples/nuxt/env.ts**
  - Import `isServer` value from the `env` object.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/t3-oss/t3-env/issues/258?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
Guria committed Aug 13, 2024
1 parent b55ca31 commit 3e3a422
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/astro/src/t3-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export const env = createEnv({
skipValidation: import.meta.env.SKIP_ENV_VALIDATION === "development",
clientPrefix: "PUBLIC_",
});

const isServer = env.isServer;
2 changes: 2 additions & 0 deletions examples/nextjs/app/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ export const env = createEnv({
},
extends: [vercel()],
});

const isServer = env.isServer;
2 changes: 2 additions & 0 deletions examples/nuxt/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export const env = createEnv({
NUXT_PUBLIC_GREETING: z.string(),
},
});

const isServer = env.isServer;
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export type CreateEnv<
TypeOf<ZodObject<TClient>> &
TypeOf<ZodObject<TShared>> &
UnReadonlyObject<Reduce<TExtends>>
>
> & { isServer: boolean }
>;

export function createEnv<
Expand Down Expand Up @@ -294,6 +294,7 @@ export function createEnv<
if (typeof prop !== "string") return undefined;
if (ignoreProp(prop)) return undefined;
if (!isValidServerAccess(prop)) return onInvalidAccess(prop);
if (prop === "isServer") return isServer;
return Reflect.get(target, prop);
},
// Maybe reconsider this in the future:
Expand Down

0 comments on commit 3e3a422

Please sign in to comment.