2
0

🔊 Add logs to debug invalid env

This commit is contained in:
Baptiste Arnaud
2023-08-30 18:47:57 +02:00
parent 124cb8f359
commit 96ddfadaa7
3 changed files with 23 additions and 4 deletions

View File

@ -1,9 +1,8 @@
import { gtmHeadSnippet } from '@/lib/google-tag-manager'
import { Metadata } from '@typebot.io/schemas'
import Head from 'next/head'
import Script from 'next/script'
import React from 'react'
import { isNotEmpty } from '@typebot.io/lib'
import { Metadata } from '@typebot.io/schemas/features/typebot/settings'
type SEOProps = {
url: string

View File

@ -1,7 +1,8 @@
import { Standard } from '@typebot.io/nextjs'
import { BackgroundType, Typebot } from '@typebot.io/schemas'
import { useRouter } from 'next/router'
import { SEO } from './Seo'
import { Typebot } from '@typebot.io/schemas/features/typebot/typebot'
import { BackgroundType } from '@typebot.io/schemas/features/typebot/theme/enums'
export type TypebotV3PageProps = {
url: string

21
packages/env/env.ts vendored
View File

@ -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}`