Skip to content

Commit

Permalink
fix: guard env with if statement before parse it with zod
Browse files Browse the repository at this point in the history
  • Loading branch information
rifandani committed Mar 19, 2024
1 parent 9cdb057 commit d06e7b9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/modules/shared/configs/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ export const envSchema = z.object({
})

export const env = (() => {
const appTitle = envSchema.shape.VITE_APP_TITLE.parse(import.meta.env.VITE_APP_TITLE ?? 'unknown-VITE_APP_TITLE')
const apiBaseUrl = envSchema.shape.VITE_API_BASE_URL.parse(import.meta.env.VITE_API_BASE_URL ?? 'unknown-VITE_API_BASE_URL')
let appTitle = 'unknown-VITE_APP_TITLE'
let apiBaseUrl = 'unknown-VITE_API_BASE_URL'

if (import.meta.env.VITE_APP_TITLE)
appTitle = envSchema.shape.VITE_APP_TITLE.parse(import.meta.env.VITE_APP_TITLE)
if (import.meta.env.VITE_API_BASE_URL)
apiBaseUrl = envSchema.shape.VITE_API_BASE_URL.parse(import.meta.env.VITE_API_BASE_URL)

return {
appTitle,
Expand Down

0 comments on commit d06e7b9

Please sign in to comment.