Skip to content

Commit

Permalink
chore: add client/server env variables boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfosouzamenezes committed Dec 31, 2023
1 parent 09cb66f commit e8c4bf6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@t3-oss/env-nextjs": "^0.7.1",
"lucide-react": "^0.301.0",
"next": "14.0.4",
"react": "^18",
Expand Down
28 changes: 13 additions & 15 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'

const envSchema = z.object({
NEXT_PUBLIC_API_BASE_URL: z.string().url(),
APP_URL: z.string().url(),
})

const parsedEnv = envSchema.safeParse(process.env)
export const env = createEnv({
server: {
APP_URL: z.string().url(),
},

if (!parsedEnv.success) {
console.error(
'Variáveis de ambiente inválidas!',
parsedEnv.error.flatten().fieldErrors,
)
client: {
NEXT_PUBLIC_API_BASE_URL: z.string().min(1),
},

throw new Error('Variáveis de ambiente inválidas!')
}

export const env = parsedEnv.data
runtimeEnv: {
APP_URL: process.env.APP_URL,
NEXT_PUBLIC_API_BASE_URL: process.env.NEXT_PUBLIC_API_BASE_URL,
},
})

0 comments on commit e8c4bf6

Please sign in to comment.