From 7dd14b8a5e4d9dcf2bbad19908bab4b4c3c6f93b Mon Sep 17 00:00:00 2001 From: aldin4u Date: Wed, 21 Jan 2026 09:30:12 +0000 Subject: [PATCH 1/3] fix(build): pass VITE_PRIVY_APP_ID env var to fix Privy app ID on staging - Add VITE_PRIVY_APP_ID to build script to ensure Cloudflare Pages env var is passed to Vite - Fixes issue where staging was using dev Privy app ID instead of production app ID - Vite doesn't automatically load system env vars, they must be explicitly passed --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38473dde..4ba65fc8 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "dev:functions": "wrangler pages dev build --port 5173 --live-reload", - "build": "NODE_OPTIONS='--max-old-space-size=8192' VITE_COMMIT_SHA=$CF_PAGES_COMMIT_SHA VITE_VERSION=$npm_package_version vite build", + "build": "NODE_OPTIONS='--max-old-space-size=8192' VITE_PRIVY_APP_ID=$VITE_PRIVY_APP_ID VITE_COMMIT_SHA=$CF_PAGES_COMMIT_SHA VITE_VERSION=$npm_package_version vite build", "preview": "vite preview", "test": "vitest", "test:watch": "eslint . && vitest", From da9176ce02295239b1f3e1343542061e5e447f14 Mon Sep 17 00:00:00 2001 From: aldin4u Date: Wed, 21 Jan 2026 09:36:15 +0000 Subject: [PATCH 2/3] fix(vite): use loadEnv to properly load VITE_PRIVY_APP_ID from environment - Update vite.config.js to use loadEnv() function - Explicitly define VITE_PRIVY_APP_ID in the define section - This ensures environment variables from Cloudflare Pages are properly loaded - Fallback from Option 1 which didn't work on Cloudflare Pages --- vite.config.js | 73 +++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/vite.config.js b/vite.config.js index 3b88a712..b95a5eb7 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,6 +1,6 @@ import react from '@vitejs/plugin-react'; import path from 'path'; -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import dynamicImport from 'vite-plugin-dynamic-import'; import svgr from 'vite-plugin-svgr'; import basicSsl from '@vitejs/plugin-basic-ssl'; @@ -10,40 +10,51 @@ import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -export default defineConfig({ - plugins: [react(), svgr(), dynamicImport(), basicSsl()], - build: { - outDir: 'build', - commonjsOptions: { transformMixedEsModules: true }, - rollupOptions: { - external: ['/functions/**'], +export default defineConfig(({ mode }) => { + // Load env file based on `mode` in the current working directory. + // Set the third parameter to '' to load all env regardless of the `VITE_` prefix. + const env = loadEnv(mode, process.cwd(), ''); + + return { + plugins: [react(), svgr(), dynamicImport(), basicSsl()], + build: { + outDir: 'build', + commonjsOptions: { transformMixedEsModules: true }, + rollupOptions: { + external: ['/functions/**'], + }, }, - }, - resolve: { - alias: { - '@': path.join(__dirname, 'src/apps'), - crypto: 'crypto-browserify', + resolve: { + alias: { + '@': path.join(__dirname, 'src/apps'), + crypto: 'crypto-browserify', + }, }, - }, - test: { - globals: true, - environment: 'jsdom', - setupFiles: './src/test-utils/setupTests.ts', define: { - global: 'globalThis', + // Explicitly expose VITE_PRIVY_APP_ID to the app + // This ensures it's available even if not in .env files + 'import.meta.env.VITE_PRIVY_APP_ID': JSON.stringify(env.VITE_PRIVY_APP_ID), + }, + test: { + globals: true, + environment: 'jsdom', + setupFiles: './src/test-utils/setupTests.ts', + define: { + global: 'globalThis', + }, + pool: 'forks', }, - pool: 'forks', - }, - server: { - https: true, - host: '0.0.0.0', - proxy: { - '/api/coinbase': { - target: 'https://api.cdp.coinbase.com', - changeOrigin: true, - rewrite: (path) => path.replace(/^\/api\/coinbase/, ''), - secure: true, + server: { + https: true, + host: '0.0.0.0', + proxy: { + '/api/coinbase': { + target: 'https://api.cdp.coinbase.com', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api\/coinbase/, ''), + secure: true, + }, }, }, - }, + }; }); From 316152f39b7b4dd0e4735ba6aa73e1ab73fe86e0 Mon Sep 17 00:00:00 2001 From: aldin4u Date: Wed, 21 Jan 2026 09:43:05 +0000 Subject: [PATCH 3/3] fix(vite): use process.env directly for VITE_PRIVY_APP_ID - Change to use process.env.VITE_PRIVY_APP_ID with fallback to loadEnv - Ensures Cloudflare Pages system environment variables take priority - Fixes issue where loadEnv was using dev mode instead of production env vars --- vite.config.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vite.config.js b/vite.config.js index b95a5eb7..96744c6b 100644 --- a/vite.config.js +++ b/vite.config.js @@ -32,8 +32,11 @@ export default defineConfig(({ mode }) => { }, define: { // Explicitly expose VITE_PRIVY_APP_ID to the app - // This ensures it's available even if not in .env files - 'import.meta.env.VITE_PRIVY_APP_ID': JSON.stringify(env.VITE_PRIVY_APP_ID), + // Use process.env directly to ensure Cloudflare Pages env vars are picked up + // Fallback to loadEnv value if not in process.env + 'import.meta.env.VITE_PRIVY_APP_ID': JSON.stringify( + process.env.VITE_PRIVY_APP_ID || env.VITE_PRIVY_APP_ID + ), }, test: { globals: true,