Closed weyert closed 4 years ago
Hmm this works on the example site.
The format of your callback URL looks right, so I'd double check the Client ID and Client Secret for GitHub.
Is this happening locally or in production or both?
You should be able to get it running on locahost too, but the way GiHub OAuth works, you'll need to create a second application to test locally (with a localhost callback URL and different ID/Secret) as unlike most providers, you can't specify multiple callback URLs on GitHub.
I have tried it out looks locally now and it's working fine but fails on the internet. I am wondering if something gets removed from the query string on the way reaching my Next.js application. I will have to do some digging. Need to find a way to easy dump all headers and query parameters of incoming requests.
Thanks for helping me :)
Ah no worries, if it's working locally that's good!
I could guess it's possibly the ID / Secret values, maybe missing a character or something (or extra whitespace like a space at the end after copy/pasting). If deploying to Vercel you could try deleting them and re-adding the environment variables in the control panel. I always manage to do this somehow, even though I try to be super careful.
I will try to hard-code the values first :))
Got it working, sadly, not sure what did the trick
Having the same problem. Works locally, have two oauth applications on github one for local and one for production. Not really sure how to debug this. I set debug to true but the logs on vercel only give me minimal information. Already tried resetting the env a few times.
looks like it adds some spaces in front of the key and secret, paste them into a text editor first and remove.
Thanks for the follow up!
I almost wonder if we should trim()
them or warn if they are found as it's such an annoying thing and common to trip up on.
@timcash could you clarify exactly what has spaces? experiencing this issue (works in dev, not production)
@timcash could you clarify exactly what has spaces? experiencing this issue (works in dev, not production)
What tends to happen is errors in pasting in either Client ID or Client Secret into the terminal or web UI - introducing typos or spaces into the environment variable values.
Removing and re-adding them usually the easiest way to resolve :-)
Oh okay, that is much more straightforward than I thought it was! And my issue was about "HTTP" vs "HTTPS" so yep a typo.
OMG!!! I had this problem with google but this post saved me!
I tried hard coding and cleared the cache, and Done :)
I cant find too why It's work locally but not when it deployed on server.
I think my issue was mixing URLs: http://localhost and http://127.0.0.1 . Using one solved my issue.
Your question I am wondering what I am doing wrong, each time when I try to sign into my application using GitHub OAuth I am getting the
oAuthCallback
-error back in the application logs it suggests invalid state or code. Only I am not sure whyWhat are you trying to do I am trying to add Next Auth.js to my application using GitHub only it's not working. I have copied the
[...nextAuth].js
file from thenextauthjs-example
-repository. I have checked that environment variables are correctly loaded and have the expectedclient id
andclient secret
for my GitHub OAuth app.My steps:
https://domain.com/api/auth/callback/github
This redirect url that GitHub generates has has forstate
-query parameter the same value that NextAuthjs used for the authorise urlhttps://domain.com/api/auth/error?error=oAuthCallback
What am I doing wrong? Do I have something misconfigured?
Feedback Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.