Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having the VERCEL env variable set breaks dev server (rewrites to HTTPS & trigger ERR_SSL_PROTOCOL_ERROR) #8385

Closed
benjaminwaterlot opened this issue Aug 22, 2023 · 4 comments
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@benjaminwaterlot
Copy link

benjaminwaterlot commented Aug 22, 2023

Reproduction URL

https://github.com/nextauthjs/next-auth-example

Describe the issue

→ Having the VERCEL env variable set to any value breaks the dev server.

Specifically, it seems to:

  • ignore NEXTAUTH_URL entirely,
  • rewrite every call to the next-auth endpoints to https, leading to ssl errors if you're not developing on a https dev server

Problem : the Vercel dev CLI (vercel env pull) adds this variable automatically to your env file! ⚠️

See https://vercel.com/docs/cli/env

Specifically, in a development environment it adds:

VERCEL="1"
VERCEL_ENV="development"
VERCEL_GIT_COMMIT_AUTHOR_LOGIN=""
VERCEL_GIT_COMMIT_AUTHOR_NAME=""
VERCEL_GIT_COMMIT_MESSAGE=""
VERCEL_GIT_COMMIT_REF=""
VERCEL_GIT_COMMIT_SHA=""
VERCEL_GIT_PREVIOUS_SHA=""
VERCEL_GIT_PROVIDER=""
VERCEL_GIT_PULL_REQUEST_ID=""
VERCEL_GIT_REPO_ID=""
VERCEL_GIT_REPO_OWNER=""
VERCEL_GIT_REPO_SLUG=""
VERCEL_URL=""

Therefore, VERCEL="1" should probably not be used to determine if the build is running on Vercel or hosted on Vercel. I suppose VERCEL_ENV or VERCEL_URL could be used to ensure that instead.

ℹ️ Strangely enough the problem only started with next@13.4.13-canary.0

How to reproduce

Set VERCEL="1" in .env.local in any next-auth app.

Try to trigger any call to the /api/auth/... endpoints.

The call will fail if you're on a http dev server, and in any case NEXTAUTH_URL will be ignored.

Expected behavior

VERCEL should not be used alone to determine if the app is built / running on Vercel servers ; therefore the app should work in development even with VERCEL="1", because that's the default for the Vercel env CLI.

In video

CleanShot.2023-08-22.at.11.07.44.mp4

Workaround

I currently workaround by overriding my dev scripts:

"dev": "VERCEL='' next dev"
@benjaminwaterlot benjaminwaterlot added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Aug 22, 2023
@benjaminwaterlot benjaminwaterlot changed the title Having the VERCEL env variable set breaks dev server (rewrites to HTTPS & trigger ERR_SSL_PROTOCOL_ERROR) Having the VERCEL env variable set breaks dev server (rewrites to HTTPS & trigger ERR_SSL_PROTOCOL_ERROR) Aug 22, 2023
@balazsorban44
Copy link
Member

duplicate of #7962

@hamirmahal
Copy link
Contributor

I just ran into the ERR_SSL_PROTOCOL_ERROR issue a few minutes ago and fixed it by commenting out VERCEL="1" in .env.

I think I got VERCEL="1" because I did vercel env pull .env, which is what https://vercel.com/guides/nextjs-prisma-postgres#step-2-set-up-your-vercel-postgres-database said to do.

@jearthman
Copy link

Hmm I've been having the same issue with ERR_SSL_PROTOCOL_ERROR. I commented out VERCEL in my env files and added VERCEL="" to my dev script in package.json. I'm on Next version 13.5.3.

@balazsorban44 i have #8722 open if you want to merge it here.

Have any other work arounds been found?

@toniopelo
Copy link

There is a more convenient workaround I just found. That allows you to still use vercel env pull without having to manually remove VERCEL="1" every time. I explained it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

5 participants