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

Setup github login #28

Closed
xedro98 opened this issue Jun 17, 2023 · 52 comments · Fixed by #76
Closed

Setup github login #28

xedro98 opened this issue Jun 17, 2023 · 52 comments · Fixed by #76

Comments

@xedro98
Copy link

xedro98 commented Jun 17, 2023

How do I setup the github login? I followed the intruction byt when i click login and authorize my github account, the chat UI just regreshes and still shows Login option, when I click Login again, it just refreshes the page.

@yashug
Copy link

yashug commented Jun 17, 2023

@xedro98 hope you have followed the instructions on this page to create a GitHub id and secret. if your running this locally, make sure you add a home page url and Authorization callback URL to http://localhost:3000/

@skorfmann
Copy link

Get the same issue.

  • Deployed to Vercel
  • Github oauth app configured
  • both github env vars are set
  • Vercel logs are not showing anything special when logging in
  • Cookies are set / sent

However, the UI is still in logged out mode. When sending a chat message, a 401 error is returned.

@CarlosZiegler
Copy link
Contributor

Check if KV datastore are workin, check env of KV.

@songispm
Copy link

How to set the github callback URL?

https://example.com/api/auth/callback/github

Is that so?

@songispm
Copy link

How do I setup the github login? I followed the intruction byt when i click login and authorize my github account, the chat UI just regreshes and still shows Login option, when I click Login again, it just refreshes the page.

same to me

@hembara
Copy link

hembara commented Jun 18, 2023

How do I setup the github login? I followed the intruction byt when i click login and authorize my github account, the chat UI just regreshes and still shows Login option, when I click Login again, it just refreshes the page.

same to me

same to me. And I've used the same callback URL - ".../api/auth/callback/github"

@seraj
Copy link

seraj commented Jun 18, 2023

image
here is my environment variables.
401 error on chat api received. The login api is working, but the header is blank.only the login button appears

@CarlosZiegler
Copy link
Contributor

Same here, investigating why that not work on prod. Local works fine.
All fine without auth errors but get 401 if send chat conversation.

@CarlosZiegler
Copy link
Contributor

I see that i get my user:
image
But then is like refresh page. I see cookies on Browser.

@guotingchao
Copy link

same problem +1

@bakharew
Copy link

Same here, investigating why that not work on prod. Local works fine.
All fine without auth errors but get 401 if send chat conversation.

Same for me

@bakharew
Copy link

All fine without auth errors but get 401 if send chat conversation.

For some reason, an Openai key in the .env file has been reset. Setting it up again resolved the issue

@CarlosZiegler
Copy link
Contributor

I don’t have issue with OpenAI , Th error is with Auth, on Prod not works only locally.

@CarlosZiegler
Copy link
Contributor

This happens because the app check Auth before send request. I don’t see my GitHub username after logging.

@tuhuynh27
Copy link

I have the same issue :(

@ThiLourenco
Copy link

same problem

@mathu97
Copy link

mathu97 commented Jun 19, 2023

+1 same problem on prod deployment, works fine on local

@tomas2387
Copy link
Contributor

I got it working locally, but I can't make it work when I deploy it on vercel... weird
image

@tomas2387
Copy link
Contributor

Could it be this?
nextauthjs/next-auth#5268 (comment)

@LeEricCH
Copy link

Same issue here, sign-in works fine locally but not in prod on vercel. When signing in it sets the cookie for the session (also tried with Google) but it doesn't sign-in. The edge function returns 200 in the Vercel logs with the callback to the auth endpoint.
Any fix so far? @jaredpalmer

@Hassan-neu
Copy link

How to set the github callback URL?

https://example.com/api/auth/callback/github

Is that so?

change "example.com" to your app's URL (the one assigned on vercel)

@Hassan-neu
Copy link

If you've ever had a place in your code where you made api call to https://localhost:300... (that has to do with github login or any other provider) just change it to https://yourapp'sdeploymentURL... or use nullish coalescing to make calls to both local or deployment URL

@hembara
Copy link

hembara commented Jun 20, 2023

Has someone managed to find a solution for the problem yet?

@balazsorban44
Copy link
Member

Hi folks, NextAuth.js maintainer here.

The callback URL for github should be:

  • Local: http://localhost:3000/api/auth/callback/github
  • Prod: https://example.com/api/auth/callback/github

Docs: https://authjs.dev/reference/core/providers_github#callback-url

(Note, ai-chatbot uses the next-auth@experimental version, found here, further documentation here)

If this does not work, could someone link to their project? 🙏

Instead of adding "same issue" or "how to fix" comments, consider adding a 👍 to the issue description instead

@conradkoh
Copy link

@balazsorban44 I faced the same issue. The reproduction steps are:

  1. Configure the local environment with all the necessary environment variables.
  2. Configure the callback as described above (http://localhost:3000/api/auth/callback/github)
  3. Test that login is working correctly - click login, github login screen appears, redirects back to app, state changed to logged in.

Repeat the steps above, but for production instead, with instances of http://localhost:3000 replaced with https://example.com. You can find a link to my fork here.

Result: Login succeeds, but the login state on the frontend remains unchanged and requests for a login. Chat history button also does not show.

@balazsorban44
Copy link
Member

Thank you @conradkoh, I'll take a look! FYI, I just pushed some updates (#55, #56) to this repo, make sure those are incorporated.

@CarlosZiegler
Copy link
Contributor

CarlosZiegler commented Jun 20, 2023 via email

@balazsorban44
Copy link
Member

Yes, I can reproduce this when deployed. Looking into it right now.

@wzono
Copy link

wzono commented Jun 21, 2023

Same problems, I'm curious about why https://chat.vercel.ai/ works as expect ? maybe it works with vercel provider?

@yunwuu
Copy link

yunwuu commented Jun 21, 2023

@wzono It doesn't work with vercel provider as well. It's weird, waiting for developers to solve this problem. I just subscribed Vercel pro plan to deploy this project but it doesn't work now :(

@pomber
Copy link

pomber commented Jun 21, 2023

Looks like export const runtime = 'edge' in app/api/auth/[...nextauth]/route.ts was the problem. Right @jaredpalmer?

Removing it from my app fixed this issue.

@SapiensID
Copy link

@pomber removing export const runtime = 'edge' in route.ts did not solve it for me.

@swyxio
Copy link
Contributor

swyxio commented Jun 21, 2023

gotta say i'm very puzzled that the deployed site works and just forking it and filling in the env vars does not seem to work. what is wrong with my mental model? how could we be struggling so much? serverless was supposed to solve all this

@tomas2387
Copy link
Contributor

tomas2387 commented Jun 22, 2023

Wow.
Changing from

export const runtime = 'edge'

to

export const runtime = 'nodejs'

fixed it for me.

PS: I updated my code with the latest changes too
f2ae20d

@conradkoh
Copy link

@tomas2387 that's interesting. may I know which route you changed the runtime for?

Off the top of my head, I'm wondering if it has anything to do with the caching implemented, where perhaps the navigation is getting cached and not invalidated after the login completes.

I haven't dug too much into the details of next13 tbh, but just posting this here to seed the idea in case someone more experienced can help validate this.

@conradkoh
Copy link

The original reproduced issue is mitigated by disabling caching in the middleware. I am still not really sure how the caching can be more granularly disabled for the header, and also the root cause of the issue.

The commit that fixes this can be found here.

This was inspired by a separate issue raised here in the next-auth library.

@balazsorban44 I think you were involved in that issue thread as well, so perhaps you would have a better idea of what's going on under the hood here.


On a separate note, I'm not sure if there is a bug somewhere but it seems like using the chat functionality does not require login. Can't tell if it is a bug or intended behavior. imo it's a bug.

@balazsorban44
Copy link
Member

balazsorban44 commented Jun 22, 2023

I released a fix, you can run pnpm up @auth/nextjs. See the details in #76. Can someone try this and report back? (Your lockfile should reference @auth/nextjs@0.0.0-manual.179c08d4)

Tested it here: https://ai-chatbot-28-conrad.vercel.app/

Login should work fine there.

@mathu97
Copy link

mathu97 commented Jun 22, 2023

thank you @balazsorban44, updating @auth/nextjs fixes it!

@swyxio
Copy link
Contributor

swyxio commented Jun 22, 2023

@balazsorban44 signin is working but chat is broken https://www.loom.com/share/68bb20215d3046f8bfa6fb6906f4102f

@joseluistello
Copy link

I have the same problem logging with github

  1. I made the pnpm up @auth/nextjs upgrade
  2. I change export const runtime = 'edge' to export const runtime = 'nodejs'

OAuth Github

image

Logs

image

Can someone help me, please?

https://github.com/joseluistello/trifecta-ai

@balazsorban44
Copy link
Member

@swyxio I cannot seem to be able to look at your Loom. :thinking:

@joseluistello There is a link in the error message, you can check it out for more info: https://errors.authjs.dev/#missingsecret (TLDR; create an AUTH_SECRET environment variable)

@joseluistello
Copy link

While I was upgrading pnpm up @auth/nextjs I encountered another error, I can no longer deploy locally.
image

image

@balazsorban44

@balazsorban44
Copy link
Member

balazsorban44 commented Jun 24, 2023

@joseluistello your reproduction repo works for me locally, both dev and buils&start. Sounds like you might have a wrong NEXTAUTH_URL value. See this repo for the default: https://github.com/vercel-labs/ai-chatbot/blob/5912336152af068e04ce6696253f1e2c9acc3fd6/.env.example#L9 or better yet, you can just remove this environment variable. Should not actually be necessary. (Did a cleanup of this in #80)

For anyone else having further issues, please open a new issue with an attached reproduction.

You can see a deployed (Vercel) version #28 (comment) with working login/logout, so I need to see your code to make sure you followed the steps #28 (comment) correctly.

@joseluistello
Copy link

Thanks so much for your help, Orbán, I was able to get the authentication working with github @balazsorban44 💯

@CarlosZiegler
Copy link
Contributor

Works for me too, Thanks

@SamiHK
Copy link

SamiHK commented Jun 26, 2023

Edit: It works for me too (on localhost)
I deployed the site to Vercel and it now shows login with Gihtub button even after logging in.
Check!

Second Edit: Production works fine after removing NEXTAUTH_URL

@rubickecho
Copy link

Hi folks, NextAuth.js maintainer here.

The callback URL for github should be:

  • Local: http://localhost:3000/api/auth/callback/github
  • Prod: https://example.com/api/auth/callback/github

Docs: https://authjs.dev/reference/core/providers_github#callback-url

(Note, ai-chatbot uses the next-auth@experimental version, found here, further documentation here)

If this does not work, could someone link to their project? 🙏

Instead of adding "same issue" or "how to fix" comments, consider adding a 👍 to the issue description instead

yes, I think this can also be explained in the README.md, which is especially useful for beginners.

@sytpb
Copy link

sytpb commented Sep 21, 2023

@xedro98 hope you have followed the instructions on this page to create a GitHub id and secret. if your running this locally, make sure you add a home page url and Authorization callback URL to http://localhost:3000/

could you give more details about this . met the same problem running on local.

@sytpb
Copy link

sytpb commented Oct 24, 2023

The commit that fixes this can be found here.

This was inspired by a separate issue raised here in the next-auth library.

how about npm ?

@RushilJalal
Copy link

The error I get when i run pnpm up @auth/nextjs

image

@RushilJalal
Copy link

Github Auth works perfectly locally, but stops working as soon as I deploy it on Vercel.
Can someone help me?
I created a discussion with all necessary errors here
nextauthjs/next-auth#11279

@RushilJalal
Copy link

RushilJalal commented Jun 28, 2024

I released a fix, you can run pnpm up @auth/nextjs. See the details in #76. Can someone try this and report back? (Your lockfile should reference @auth/nextjs@0.0.0-manual.179c08d4)

Tested it here: https://ai-chatbot-28-conrad.vercel.app/

Login should work fine there.

Login in fact doesn't work fine
But this works fine https://ai-chatbot.vercel.sh/
@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.