vercel / ai-chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
https://chat.vercel.ai
Other
6.16k stars 1.91k forks source link

Setup github login #28

Closed xedro98 closed 1 year ago

xedro98 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

Get the same issue.

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

CarlosZiegler commented 1 year ago

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

songispm commented 1 year ago

How to set the github callback URL?

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

Is that so?

songispm commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I see that i get my user:

image

But then is like refresh page. I see cookies on Browser.

guotingchao commented 1 year ago

same problem +1

bakharew commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

CarlosZiegler commented 1 year ago

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

tuhuynh27 commented 1 year ago

I have the same issue :(

ThiLourenco commented 1 year ago

same problem

mathu97 commented 1 year ago

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

tomas2387 commented 1 year ago

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

tomas2387 commented 1 year ago

Could it be this? https://github.com/nextauthjs/next-auth/issues/5268#issuecomment-1281173538

LeEricCH commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

balazsorban44 commented 1 year ago

Hi folks, NextAuth.js maintainer here.

The callback URL for github should be:

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? :pray:

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

conradkoh commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

Thanks for the explanation , I will try it today, I ask my self why it works correctly locally and on prod not works and don’t see some error on logs? Did you tested in PROD?

Em ter., 20 de jun. de 2023 às 17:41, Balázs Orbán @.***> escreveu:

Thank you @conradkoh https://github.com/conradkoh, I'll take a look! FYI, I just pushed some updates (#55 https://github.com/vercel-labs/ai-chatbot/pull/55, #56 https://github.com/vercel-labs/ai-chatbot/pull/56) to this repo, make sure those are incorporated.

— Reply to this email directly, view it on GitHub https://github.com/vercel-labs/ai-chatbot/issues/28#issuecomment-1599046715, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJIOGU4SYN46G2XSC7K2XRLXMHAD7ANCNFSM6AAAAAAZKBCXWA . You are receiving this because you commented.Message ID: @.***>

--

Mit freundlichen Grüßen

Carlos Ziegler

Mobil: 01727572563

balazsorban44 commented 1 year ago

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

wzono commented 1 year ago

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

yunwuu commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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

swyxio commented 1 year ago

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 commented 1 year ago

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 https://github.com/vercel-labs/ai-chatbot/pull/74/commits/f2ae20d26b3d0f22c5aa78a67436449a6a07a590

conradkoh commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

swyxio commented 1 year ago

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

joseluistello commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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

image

@balazsorban44

balazsorban44 commented 1 year ago

@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 https://github.com/vercel-labs/ai-chatbot/issues/28#issuecomment-1602571012 with working login/logout, so I need to see your code to make sure you followed the steps https://github.com/vercel-labs/ai-chatbot/issues/28#issuecomment-1602571012 correctly.

joseluistello commented 1 year ago

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

CarlosZiegler commented 1 year ago

Works for me too, Thanks

SamiHK commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 11 months ago

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 commented 2 months ago

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

image