|
| 1 | +import { createEnv } from "@t3-oss/env-nextjs"; |
| 2 | +import { z } from "zod"; |
| 3 | + |
| 4 | +export const env = createEnv({ |
| 5 | + /** |
| 6 | + * Specify your server-side environment variables schema here. This way you can ensure the app |
| 7 | + * isn't built with invalid env vars. |
| 8 | + */ |
| 9 | + server: {}, |
| 10 | + |
| 11 | + /** |
| 12 | + * Specify your client-side environment variables schema here. This way you can ensure the app |
| 13 | + * isn't built with invalid env vars. To expose them to the client, prefix them with |
| 14 | + * `NEXT_PUBLIC_`. |
| 15 | + */ |
| 16 | + client: { |
| 17 | + NEXT_PUBLIC_STELLAR_NETWORK: z.enum(["testnet", "mainnet", "futurenet"]), |
| 18 | + NEXT_PUBLIC_SOROBAN_RPC_URL: z.string().url(), |
| 19 | + NEXT_PUBLIC_HORIZON_URL: z.string().url(), |
| 20 | + NEXT_PUBLIC_AXIONVERA_VAULT_CONTRACT_ID: z |
| 21 | + .string() |
| 22 | + .regex(/^C[A-Z0-9]{55}$/, "Contract ID must start with 'C' and be 56 characters long"), |
| 23 | + NEXT_PUBLIC_AXIONVERA_TOKEN_CONTRACT_ID: z |
| 24 | + .string() |
| 25 | + .regex(/^C[A-Z0-9]{55}$/, "Contract ID must start with 'C' and be 56 characters long"), |
| 26 | + }, |
| 27 | + |
| 28 | + /** |
| 29 | + * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g. |
| 30 | + * middlewares) or client-side so we need to destruct manually. |
| 31 | + */ |
| 32 | + runtimeEnv: { |
| 33 | + NEXT_PUBLIC_STELLAR_NETWORK: process.env.NEXT_PUBLIC_STELLAR_NETWORK, |
| 34 | + NEXT_PUBLIC_SOROBAN_RPC_URL: process.env.NEXT_PUBLIC_SOROBAN_RPC_URL, |
| 35 | + NEXT_PUBLIC_HORIZON_URL: process.env.NEXT_PUBLIC_HORIZON_URL, |
| 36 | + NEXT_PUBLIC_AXIONVERA_VAULT_CONTRACT_ID: process.env.NEXT_PUBLIC_AXIONVERA_VAULT_CONTRACT_ID, |
| 37 | + NEXT_PUBLIC_AXIONVERA_TOKEN_CONTRACT_ID: process.env.NEXT_PUBLIC_AXIONVERA_TOKEN_CONTRACT_ID, |
| 38 | + }, |
| 39 | + /** |
| 40 | + * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially |
| 41 | + * useful for Docker builds. |
| 42 | + */ |
| 43 | + skipValidation: !!process.env.SKIP_ENV_VALIDATION, |
| 44 | + /** |
| 45 | + * Makes it so that empty strings are treated as undefined. |
| 46 | + * `SOME_VAR: z.string()` and `SOME_VAR=''` will throw an error. |
| 47 | + */ |
| 48 | + emptyStringAsUndefined: true, |
| 49 | +}); |
0 commit comments