🔊 Add logs to debug invalid env
This commit is contained in:
21
packages/env/env.ts
vendored
21
packages/env/env.ts
vendored
@ -1,7 +1,11 @@
|
||||
import { createEnv } from '@t3-oss/env-nextjs'
|
||||
import { z } from 'zod'
|
||||
import { ZodError, z } from 'zod'
|
||||
import { getRuntimeVariable } from './getRuntimeVariable'
|
||||
|
||||
declare const window: {
|
||||
__ENV?: any
|
||||
}
|
||||
|
||||
const boolean = z.enum(['true', 'false']).transform((value) => value === 'true')
|
||||
|
||||
const baseEnv = {
|
||||
@ -313,6 +317,21 @@ export const env = createEnv({
|
||||
...sentryEnv.runtimeEnv,
|
||||
...posthogEnv.runtimeEnv,
|
||||
},
|
||||
onValidationError: (error: ZodError) => {
|
||||
console.log(
|
||||
'[DEBUG]',
|
||||
"typeof window !== 'undefined'",
|
||||
typeof window !== 'undefined'
|
||||
)
|
||||
if (typeof window !== 'undefined') {
|
||||
console.log('[DEBUG]', 'window.__ENV', window.__ENV)
|
||||
}
|
||||
console.error(
|
||||
'❌ Invalid environment variables:',
|
||||
error.flatten().fieldErrors
|
||||
)
|
||||
throw new Error('Invalid environment variables')
|
||||
},
|
||||
onInvalidAccess: (variable: string) => {
|
||||
throw new Error(
|
||||
`❌ Attempted to access a server-side environment variable on the client: ${variable}`
|
||||
|
Reference in New Issue
Block a user