shadcn-ui / taxonomy

An open source application built using the new router, server components and everything new in Next.js 13.
https://tx.shadcn.com
MIT License
18.62k stars 2.58k forks source link

Login not Working in Vercel Deploy #104

Open benedictusalvian opened 1 year ago

benedictusalvian commented 1 year ago

Hey all, I have set all the env variables, but somehow log in is not working when deployed. Everything works fine locally.

I get this error through the URL: https://fyp-omega.vercel.app/login?callbackUrl=https%3A%2F%2Ffyp-omega.vercel.app%2Flogin&error=Callback

My deploy URL is https://fyp-omega.vercel.app/

I've set the following env variables in Vercel: NEXT_PUBLIC_APP_URL: https://fyp-omega.vercel.app/ NEXTAUTH_URL: https://fyp-omega.vercel.app/

And I've set GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET from GitHub, and made sure the OAuth Apps app URL and calback URL to be https://fyp-omega.vercel.app/. The GITHUB_ACCESS_TOKEN is there as well.

Everything works locally, just not in deployment.

Any help is appreciated.

image

VictorCalderon commented 1 year ago

Hello!

I think the callback url has to be something like https://fyp-omega.vercel.app/api/auth/callback/github. On the other hand, during deployment, I believe Vercel handles NEXTAUTH_URL for you, so you don't even need to set that one in production.

Best of luck.

benedictusalvian commented 1 year ago

I changed my callback URL to the one you mentioned above. Unfortunately, there is still the same error message. Quite puzzling as local is working fine.

https://fyp-omega.vercel.app/login?callbackUrl=https%3A%2F%2Ffyp-omega.vercel.app%2Flogin&error=Callback

VictorCalderon commented 1 year ago

Usually when these errors occur, you can check on your Developer Tools the status code, and a more elaborate response of what going on. These I would consider checking:

  1. It happened to me once and Auth.js just would work. I removed my production env variables for NextAuth and let Vercel handle the rest.

  2. I made sure I had the correct setup as Auth.js documents. Github is relatively simple to set up, and Shad already did the heavy lifting here. Remember the S in https for the authorization callback url (happened to me once).

  3. Make sure you're using the right credentials for production, as Github only allows one callback per token, sometimes people confuse them while setting them up for the first time (hello again, also happened to me).

Please, if possible, let us see what the console is telling you, so we can this issue together. 🚀

Lunatic83 commented 1 year ago

Hi, I'm getting the same error, and banging my head for the last 3 hours without solving the issue.

Did you maybe solve it?

Lunatic83 commented 1 year ago

Solved, it was about this issue #142. The field refresh_token_expires_in in the github account schema was missing.

NotellumCreek commented 8 months ago

Hey all, I have set all the env variables, but somehow log in is not working when deployed. Everything works fine locally.

I get this error through the URL: https://fyp-omega.vercel.app/login?callbackUrl=https%3A%2F%2Ffyp-omega.vercel.app%2Flogin&error=Callback

Are you on a test deployment? I believe that vercel generates a unique url for each test deployment.

It seems to work with credentials for me, and then it works in production. It's just the way vercel does it. This is a potential solution https://github.com/orgs/vercel/discussions/132#discussioncomment-4270119

Designandcode01 commented 1 week ago

I am also facing same login issue after deploying on vercel but I am using Kinde authentication. My url is https://medicalanddigitalsciences.vercel.app/. Please, suggest any solution?

NotellumCreek commented 1 week ago

I am also facing same login issue after deploying on vercel but I am using Kinde authentication. My url is https://medicalanddigitalsciences.vercel.app/. Please, suggest any solution?

Does it work if you use Vercel env variables in your url? https://vercel.com/docs/deployments/generated-urls