Skip to content

Conversation

@aldin4u
Copy link
Collaborator

@aldin4u aldin4u commented Jan 21, 2026

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:

- "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",

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:

  1. Check Cloudflare Pages build logs to confirm the environment variable is being passed
  2. Visit the staging URL and verify Privy authentication uses the production app ID
  3. Check browser DevTools Network tab for Privy API requests to confirm the correct app ID is being used

Summary by CodeRabbit

  • Chores

    • Build now passes an additional environment variable into the application runtime for configuration.
  • Refactor

    • Configuration loading was reorganized to centralize environment handling and ensure the new variable is consistently exposed across builds.
  • Tests

    • Test configuration adjusted to use the centralized environment handling and updated test execution settings.

✏️ Tip: You can customize this high-level summary in your review settings.

…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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Build script
package.json
Added VITE_PRIVY_APP_ID=$VITE_PRIVY_APP_ID to the vite build environment variables in the build script.
Vite configuration
vite.config.js
Converted default export to defineConfig(({ mode }) => { ... }), imported and used loadEnv(mode, process.cwd(), ''), exposed import.meta.env.VITE_PRIVY_APP_ID via define, and added define for global plus test.pool: 'forks'. Server/proxy/alias and plugins/build settings retained with minor restructuring.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit peeks into the build, 🐇
Env peeks out and hops along,
Privy's key now hums aloud,
Config shifts, but stays quite strong,
I nibble bytes and sing this song. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing the Privy app ID issue on staging by passing the environment variable in the build process.
Description check ✅ Passed The description thoroughly covers the problem, root cause, changes made, testing performed, and verification steps. It exceeds the template requirements with detailed technical context and clear explanation of the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 21, 2026

Deploying pillarx-debug with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 21, 2026

Deploying x with  Cloudflare Pages  Cloudflare Pages

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

View logs

…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
@github-actions github-actions bot temporarily deployed to Preview (fix/privy-app-id-env-var) January 21, 2026 09:36 Inactive
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants