Integrations

Vercel Integration

@secr/vercel pulls secrets from secr and writes them to .env.local before your Vercel build runs. Works with Next.js, Vite, Remix, and any framework that reads from .env.local.

Quick Start

1. Install the package

npm install @secr/vercel

2. Create a CLI token

secr token create --name "vercel-prod"

3. Configure Vercel environment variables

In your Vercel project settings, go to Settings → Environment Variables and add the following:

VariableValueEnvironments
SECR_TOKENsecr_tok_...All
SECR_ORGmy-orgAll
SECR_PROJECTmy-projectAll

4. Update your build command

In Settings → General → Build & Development Settings, override the build command:

npx secr-vercel && next build

Replace next build with your framework's build command (e.g. vite build, remix build).

How It Works

  1. Read environment variables secr-vercel reads SECR_TOKEN, SECR_ORG, SECR_PROJECT, and the target environment from Vercel's environment.
  2. Determine environment — Uses SECR_ENVIRONMENT if set, otherwise falls back to VERCEL_ENV (automatically set by Vercel to production, preview, or development).
  3. Pull secrets — Calls the secr API using the @secr/sdk to fetch all decrypted secrets for the resolved environment.
  4. Write .env.local — Writes the secrets as KEY=value pairs to .env.local in the working directory. Special characters and multiline values are properly escaped.
  5. Build proceeds — Your framework reads .env.local as usual during the build step.

Environment Variables

OptionTypeRequiredDescription
SECR_TOKENstringYessecr CLI token (secr_tok_...). Set in Vercel project settings.
SECR_ORGstringYesOrganization slug in secr.
SECR_PROJECTstringYesProject slug in secr.
SECR_ENVIRONMENTstringVERCEL_ENVOverride the secr environment. Falls back to VERCEL_ENV, then to "production".
SECR_API_URLstringhttps://api.secr.devsecr API base URL.

CLI Options

OptionTypeRequiredDescription
--outputstring.env.localOutput file path. Defaults to .env.local in the current directory.
Custom output path
npx secr-vercel --output .env.production && next build

Environment Mapping

When SECR_ENVIRONMENT is not set, the integration uses Vercel's VERCEL_ENV value to determine which secr environment to pull from.

Vercel ContextVERCEL_ENVsecr Environment
Productionproductionproduction
Previewpreviewpreview
Developmentdevelopmentdevelopment

To map Vercel's preview to a different secr environment (e.g. staging), set SECR_ENVIRONMENT=staging for the Preview environment scope in Vercel.

Troubleshooting

ErrorCauseFix
SECR_TOKEN environment variable is requiredThe token is not set in Vercel project settings.Add SECR_TOKEN to your Vercel environment variables.
SECR_ORG environment variable is requiredThe org slug is missing.Add SECR_ORG to your Vercel environment variables.
Secr API error: not_foundThe org, project, or environment slug does not match.Verify slugs with secr projects list and check for typos.
Build fails but .env.local is emptyThe secr-vercel command is not running before the build.Ensure the build command is npx secr-vercel && next build (with &&).

Security Notes

  • Token storage — Store the SECR_TOKEN as a sensitive environment variable in Vercel (encrypted at rest). Never commit tokens to your repository.
  • .gitignore — Ensure .env.local is in your .gitignore. Next.js does this by default, but verify for other frameworks.
  • Dedicated token — Create a separate token for Vercel builds. If a token is compromised, you can revoke it without affecting other services.
  • Environment scoping — You can scope Vercel environment variables to specific environments (Production, Preview, Development) to limit which builds can access production secrets.

Deploy with secrets from secr

npm install @secr/vercel