platforms icon indicating copy to clipboard operation
platforms copied to clipboard

Github login works in production but doesn't locally

Open mathu97 opened this issue 11 months ago • 8 comments

Has anyone been able to get auth for the latest version of this repo running locally? GitHub login doesn't work for me locally but works in production.

The callback for GitHub seems to be set correctly: Screen Shot 2023-09-09 at 8 41 30 PM

But I just get redirected back to the login page after clicking on Login with Github.

I've spent quite a while trying to debug this ... to reproduce the problems:

  • Clone the repo
  • Set required environment variables (i.e. GitHub client id & secret, Postgres URLs, etc).
  • Then run pnpm install followed by pnpm run dev

I also added some logging to the NextAuth callbacks and noticed that the session callback wasn't being triggered but the JWT one was. I'm not sure if that has something to do with this.

I don't want to have to keep deploying to prod to test my changes :/

mathu97 avatar Sep 10 '23 00:09 mathu97

@mathu97 check your env.local file and uncomment Vercel = "1" if this exist in env.local

Jace996 avatar Sep 10 '23 03:09 Jace996

@Jace996 did you mean to comment out Vercel = "1"? I saw that suggestion in another issue and did do that, but that didn't help with this problem.

This is what my .env.development.local file looks like:

# Created by Vercel CLI
POSTGRES_DATABASE=*****
POSTGRES_HOST=*****
POSTGRES_PASSWORD=*****
POSTGRES_PRISMA_URL=*****
POSTGRES_URL=*****
POSTGRES_URL_NON_POOLING=*****
POSTGRES_USER="default"
#VERCEL=""

# DON'T FORGET TO RENAME TO .env OR .env.local BEFORE PUSHING TO GIT

### DEVELOPMENT ONLY VARIABLES
# These variables need to be set for local development only

# Mandatory next-auth URL for localhost
NEXTAUTH_URL=http://app.localhost:3000
 
### PRODUCTION & DEVELOPMENT VARIABLES
# These variables need to be set for local development and when deployed on Vercel

# Change this to your own domain
NEXT_PUBLIC_ROOT_DOMAIN=loyali.app

# Vercel Blob Storage for image uploads – currently in beta, please fill out this form for access: https://tally.so/r/nPDMNd. Setup instructions: https://vercel.com/docs/storage/vercel-blob/quickstart
BLOB_READ_WRITE_TOKEN=""

# GitHub OAuth secrets for auth & login – generate these here: https://github-client-generator.vercel.app/
NEXTAUTH_SECRET=*****
AUTH_GITHUB_ID=*****
AUTH_GITHUB_SECRET=*****

# Vercel authentication token that can be found here: https://vercel.com/account/tokens
AUTH_BEARER_TOKEN=*****
# Vercel Project ID that can be found here: https://vercel.com/<org>/<project>/settings
PROJECT_ID_VERCEL=*****
# Vercel Team ID that can be found here: https://vercel.com/teams/<org>/settings
TEAM_ID_VERCEL=*****

# OpenAI API key for AI text generation – get one here: https://platform.openai.com/account/api-keys
OPENAI_API_KEY=*****

I also attached a video to show what the behaviour looks like on my side:

https://github.com/vercel/platforms/assets/14209679/057c996d-9785-4645-a287-6323861a71c2

mathu97 avatar Sep 10 '23 14:09 mathu97

https://github.com/vercel/platforms/pull/310

It works for me. Check it out.

yorsant avatar Sep 11 '23 03:09 yorsant

Same here. Login is successful but redirects to/login ;(

Morriz avatar Sep 18 '23 16:09 Morriz

I solved it indeed by setting NEXTAUTH_SECRET which seems needed for JWT enc/dec

Morriz avatar Sep 18 '23 18:09 Morriz

Same here, I do have NEXTAUTH_SECRET and I tried both commenting and un-commenting the VERCEL="1", still not working.

  • with VERCEL="1".
Screenshot 2023-12-09 at 16 46 45
  • without VERCEL="1"
Screenshot 2023-12-09 at 16 46 09

here my .env.local looks like

# Created by Vercel CLI
AUTH_BEARER_TOKEN="xxxxxx"
AUTH_GITHUB_ID="Iv1.xxxx"
AUTH_GITHUB_SECRET="919cxxxx"
BLOB_READ_WRITE_TOKEN="vercel_blobxxxx"
NEXTAUTH_SECRET="71480753cbxxxxx"
NEXTAUTH_URL="http://app.localhost:3000"
NEXT_PUBLIC_ROOT_DOMAIN="app.localhost:3000"
NX_DAEMON=""
OPENAI_API_KEY="ff"
POSTGRES_DATABASE="verceldb"
POSTGRES_HOST="ep-sparkling-dxxxx.postgres.vercel-storage.com"
POSTGRES_PASSWORD="XpECKxxxx"
POSTGRES_PRISMA_URL="postgres://default:[email protected]/verceldb?pgbouncer=true&connect_timeout=15"
POSTGRES_URL="postgres://default:[email protected]/verceldb"
POSTGRES_URL_NON_POOLING="postgres://default:Xxxxxxnt9f@ep-sparkling-xxxx.us-east-1.postgres.vercel-storage.com/verceldb"
POSTGRES_USER="default"
PROJECT_ID_VERCEL="nIj3cxxxxxMA"
TEAM_ID_VERCEL="xxxx-s-team"
TURBO_REMOTE_ONLY=""
TURBO_RUN_SUMMARY=""
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=""
#VERCEL="1" 

metrue avatar Dec 09 '23 08:12 metrue

guys, comment the

VERCEL="1"

Furthermore, you need a key in the NEXTAUTH_SECRET="here-the-key" that will be used for the JWT.

NEXT_PUBLIC_ROOT_DOMAIN="http://app.localhost:3000", after that it should work perfectly.

douglasmarianodev avatar Feb 02 '24 21:02 douglasmarianodev

guys, comment the

VERCEL="1"

Furthermore, you need a key in the NEXTAUTH_SECRET="here-the-key" that will be used for the JWT.

NEXT_PUBLIC_ROOT_DOMAIN="http://app.localhost:3000", after that it should work perfectly.

@douglasmarianodev Thank you, this worked perfectly.

Kalyankr avatar May 24 '24 21:05 Kalyankr