platforms
platforms copied to clipboard
Github login works in production but doesn't locally
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:
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 bypnpm 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 check your env.local file and uncomment Vercel = "1"
if this exist in env.local
@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
https://github.com/vercel/platforms/pull/310
It works for me. Check it out.
Same here. Login is successful but redirects to/login
;(
I solved it indeed by setting NEXTAUTH_SECRET
which seems needed for JWT enc/dec
Same here, I do have NEXTAUTH_SECRET
and I tried both commenting and un-commenting the VERCEL="1"
, still not working.
- with
VERCEL="1"
.
- without
VERCEL="1"
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"
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.
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.