Skip to content

Commit

Permalink
feat: Enforce NEXT_PUBLIC_ env key on client with TS (#1370)
Browse files Browse the repository at this point in the history
* feat: Enforce `NEXT_PUBLIC_` env key on client

* chore: add changeset

* fix: Remove @ts-check

* fix: Revert code
  • Loading branch information
chungweileong94 committed Apr 20, 2023
1 parent 19083e8 commit 18bc6a7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-frogs-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": minor
---

Enforce `NEXT_PUBLIC_` env key on client
10 changes: 7 additions & 3 deletions cli/template/base/src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ const server = z.object({
* Specify your client-side environment variables schema here. This way you can ensure the app isn't
* built with invalid env vars. To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
const client = z.object({
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
});
const client = z.object(
/** @satisfies {Record<`NEXT_PUBLIC_${string}`, import('zod').ZodType>} */ (
{
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
}
),
);

/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
Expand Down
10 changes: 7 additions & 3 deletions cli/template/extras/src/env/with-auth-prisma.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ const server = z.object({
* Specify your client-side environment variables schema here. This way you can ensure the app isn't
* built with invalid env vars. To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
const client = z.object({
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
});
const client = z.object(
/** @satisfies {Record<`NEXT_PUBLIC_${string}`, import('zod').ZodType>} */ (
{
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
}
),
);

/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
Expand Down
10 changes: 7 additions & 3 deletions cli/template/extras/src/env/with-auth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ const server = z.object({
* Specify your client-side environment variables schema here. This way you can ensure the app isn't
* built with invalid env vars. To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
const client = z.object({
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
});
const client = z.object(
/** @satisfies {Record<`NEXT_PUBLIC_${string}`, import('zod').ZodType>} */ (
{
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
}
),
);

/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
Expand Down
10 changes: 7 additions & 3 deletions cli/template/extras/src/env/with-prisma.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ const server = z.object({
* Specify your client-side environment variables schema here. This way you can ensure the app isn't
* built with invalid env vars. To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
const client = z.object({
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
});
const client = z.object(
/** @satisfies {Record<`NEXT_PUBLIC_${string}`, import('zod').ZodType>} */ (
{
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
}
),
);

/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
Expand Down

1 comment on commit 18bc6a7

@vercel
Copy link

@vercel vercel bot commented on 18bc6a7 Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.