Hello, I am trying to parse my env schema to make sure it is valid. Currently I am checking if the window is undefined and parsing the correct schemas accordingly. The problem is that the env variable is always being set to the client types even when on the server.
In the below code env always ends up as only the clientEnv types.
const parsed =
typeof window === 'undefined'
? safeParse(merge([serverEnv, clientEnv]), process.env)
: safeParse(clientEnv, destructuredEnv)
if (!parsed.success) {
console.error(
`Invalid environment variables:`,
Object.entries(flatten(parsed.issues).nested)
.map((issue, i) => `${i == 0 ? '\n-- ' : ''}${issue[0]}: ${issue[1]![0]}`)
.join('\n-- ')
)
throw new Error('Invalid environment variables!')
}
export const env = parsed.output