Skip to content

bug: syncVercelEnvVars syncs production env var for preview deployment when using NeonDB vercel integration #2714

@felix-quotez

Description

@felix-quotez

Provide environment information

(Version is 4.1.2, but likely does not matter much)

Describe the bug

When using the Vercel NeonDB integration, each preview environments gets individual env vars set just before a build starts on Vercel. Those "per preview environment" env vars are not returned by the Vercel REST API at https://api.vercel.com/v8/projects/${projectId}/env?${params}.

The problem is that syncVercelEnvVars uses the above URL to get both, env var names and their values. The synced env vars do not have the values Vercel uses during the build! Env var are not actually in sync.

To make matters worse, the Vercel NeonDB integration, automatically makes the production db env var available through the above REST API for the staging environment! This caused our trigger.dev staging environment to write to our prod db :( (In the Vercel UI this env var is "managed" by the Neon DB integration and cannot even be manually fixed.)

My suggestion is to "fix" this problem by modifying syncVercelEnvVars to only get the names of the env vars from the REST API but then reading the values from the actual build environment. Just like "syncEnvVars" does it.

(For what it's worth, follow-ups could also include:

  1. To file a feature request with Vercel to ask for a way to get the "per preview environment" env vars.
  2. To ask NeonDB to not set the prod url for staging [tbh wtf])

As a workaround, we switched to using "syncEnvVars" for the Neon related env vars.

Reproduction repo

Sorry, I hope the steps are detailed enough

To reproduce

  • Make a Vercel project
  • Use the Neon db Vercel integration
  • Build/deploy a Vercel preview environment that also deploys to trigger.dev staging env and uses syncVercelEnvVars
  • Observe that the trigger dev tasks in staging are using the production database

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions