fix(build): pass VITE_PRIVY_APP_ID env var to fix Privy app ID on staging#499
Open
fix(build): pass VITE_PRIVY_APP_ID env var to fix Privy app ID on staging#499
Conversation
…ging - 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
Contributor
📝 WalkthroughWalkthroughThe build script now passes VITE_PRIVY_APP_ID to the Vite build. The Vite config was converted to a function-based export that calls loadEnv(...) to expose VITE_PRIVY_APP_ID via define, and test settings now include a global define and pool: 'forks'. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying pillarx-debug with
|
| Latest commit: |
316152f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://72cf3feb.pillarx-debug.pages.dev |
| Branch Preview URL: | https://fix-privy-app-id-env-var.pillarx-debug.pages.dev |
Deploying x with
|
| Latest commit: |
316152f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f1015846.x-e62.pages.dev |
| Branch Preview URL: | https://fix-privy-app-id-env-var.x-e62.pages.dev |
…nment - 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
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Staging was using the dev Privy App ID (clx07qnbf07qdwlja56mg55er) instead of the production Privy App ID, even though the environment variable is configured in Cloudflare Pages.
Root Cause
Vite doesn't automatically load system environment variables during the build process. The build script was only explicitly passing VITE_COMMIT_SHA and VITE_VERSION, but not VITE_PRIVY_APP_ID. This caused Vite to fall back to loading the value from .env.example, which contains the dev app ID.
Changes
Updated the build script in package.json to explicitly pass the VITE_PRIVY_APP_ID environment variable:
This ensures that when Cloudflare Pages runs the build, it will pass the VITE_PRIVY_APP_ID environment variable (configured in Cloudflare Pages settings) to Vite, which will then embed it in the built application.
Testing
✅ Tested locally by building with a test production app ID
✅ Verified the test app ID is embedded in the built JavaScript
✅ Confirmed the dev app ID is NOT in the build
Verification Steps
After merging:
Summary by CodeRabbit
Chores
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.