[Bug] Auth login Github 404 (client_id=undefined)
📦 Platform
Self hosting Docker
📦 Deploymenet mode
client pgelite db (lobe-chat-pglite image), server db(lobe-chat-database image)
📌 Version
1.26.4
💻 Operating System
Other Linux
🌐 Browser
Chrome
🐛 Bug Description
当我用浏览器访问https://github.com/login/oauth/authorize?scope=user:email&client_id=IvxxxxxvIvpf,能正常唤起github的登陆功能,但是通过lobechat的登录却无法唤醒,发现url中client_id=undefined,但是已经正确配置了lobe-chat.env,请协助我更改错误,谢谢。
When I use a browser to access https://github.com/login/oauth/authorize?scope=user:email&client_id=IvxxxxxvIvpf, the login of github can be awakened normally, but the login through lobechat cannot be awakened. I found that client_id=undefined in the URL, but lobe-chat.env has been correctly configured. Please help me correct the error, thank you.
📷 Recurrence Steps
No response
🚦 Expected Behavior
No response
📝 Additional Information
No response
👀 @Aspoir
Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible.
非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。
Hey @Aspoir, I'm here to help you with the issue you're facing. I can assist with bug fixes, answer questions, and guide you in becoming a contributor.
The issue you're experiencing with the client_id being undefined in the OAuth URL suggests that the environment variable for the GitHub client ID might not be correctly loaded or referenced in your application. Here are some steps to troubleshoot and resolve this issue:
-
Check Environment Variables: Ensure that the
AUTH_GITHUB_IDenvironment variable is correctly set in yourlobe-chat.envfile. It should look something like this:AUTH_GITHUB_ID=your_github_client_id AUTH_GITHUB_SECRET=your_github_client_secret -
Verify Environment File Loading: Make sure that the
lobe-chat.envfile is being loaded correctly by your application. This typically involves ensuring that the file is in the correct directory and that your Docker setup is configured to load this file. -
Restart the Application: After making any changes to the environment variables, restart your Docker containers to ensure that the new configuration is applied.
-
Check Code Configuration: In the Lobe Chat codebase, verify that the
client_idis being correctly retrieved from the environment variables. This is usually done in the OAuth provider configuration section, such as insrc/app/api/auth/next-auth.ts:const { AUTH_GITHUB_ID } = process.env; -
Log Environment Variables: Add logging to your application to print out the environment variables at runtime. This can help confirm whether the variables are being loaded as expected.
-
Review Docker Configuration: Ensure that your Docker Compose or Dockerfile setup includes the necessary steps to pass environment variables into the running containers.
By following these steps, you should be able to identify where the client_id is not being set correctly and resolve the issue. If the problem persists, double-check the formatting and syntax of your lobe-chat.env file and ensure there are no typos or missing entries.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@dosubot Thank you for your reply. I changed AUTH_AUTH0_ID and AUTH_AUTH0_SECRET to AUTH_GITHUB_ID and AUTH_GITHUB_SECRET to solve this problem. However, after successfully logging into GitHub, an exception was reported when jumping to lobechat.
Is it still .env problem, or the GitHub configuration?
The NextAuth error you're encountering is likely related to a configuration issue with the environment variables. The error message specifically indicates a configuration problem, suggesting that the environment variables may not be set correctly. Ensure that the following variables are properly configured in your .env file:
NEXT_AUTH_SECRET: A secret key used to encrypt session tokens. Generate it usingopenssl rand -base64 32.NEXT_AUTH_SSO_PROVIDERS: Set this togithubfor GitHub authentication.AUTH_GITHUB_ID: Your GitHub App's Client ID.AUTH_GITHUB_SECRET: Your GitHub App's Client Secret.NEXTAUTH_URL: The callback URL for OAuth authentication. Set it if the default redirect address is incorrect.
Additionally, if you recently upgraded the lobe-chat-database, there might be issues with environment variables not taking effect properly in versions 1.51.4 and above. Consider rolling back to version 1.51.3 if necessary [1][2].
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@dosubot I checked the docker logs and found that it should be the reason for the link timeout? How can I solve it?
[auth][error] CallbackRouteError: Read more at https://errors.authjs.dev#callbackrouteerror [auth][cause]: TypeError: fetch failed at node:internal/deps/undici/undici:13502:13 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async nI (/app/.next/server/chunks/85464.js:368:14193) at async ij (/app/.next/server/chunks/85464.js:368:33314) at async iV (/app/.next/server/chunks/85464.js:368:40333) at async i5 (/app/.next/server/chunks/85464.js:368:51902) at async i3 (/app/.next/server/chunks/85464.js:368:56596) at async tr.do (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]_react-dom@19._dpqdy2s6ykudta5c6xlgnxgea4/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:17582) at async tr.handle (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]_react-dom@19._dpqdy2s6ykudta5c6xlgnxgea4/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:22212) at async doRender (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]_react-dom@19._dpqdy2s6ykudta5c6xlgnxgea4/node_modules/next/dist/server/base-server.js:1452:42) [auth][details]: { "name": "ConnectTimeoutError", "code": "UND_ERR_CONNECT_TIMEOUT", "provider": "github" }
The error you're encountering, ConnectTimeoutError, indicates that the connection to GitHub is timing out. Here are some steps to troubleshoot and resolve this issue:
-
Network Configuration: Ensure that your Docker containers have proper network access. Verify that there are no firewall rules or network policies blocking outbound connections to GitHub.
-
DNS Resolution: Check that DNS resolution is working correctly within your Docker containers. You can test this by running a simple DNS query or ping command from within the container.
-
Increase Timeout Settings: If the network is slow, consider increasing the timeout settings for network requests. This can be done by adjusting the network request timeout configuration in your application. In the Lobe Chat codebase, you can adjust the
ASYNC_TASK_TIMEOUTvalue in thesrc/database/server/models/asyncTask.tsfile [1]. -
Environment Variables: Double-check your environment variables to ensure they are correctly set and loaded. This includes
NEXTAUTH_URL,AUTH_GITHUB_ID, andAUTH_GITHUB_SECRET. -
Restart Services: After making changes, restart your Docker containers to apply the new configurations.
By following these steps, you should be able to address the timeout issue and ensure a successful connection to GitHub for authentication.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@dosubot I have tried many methods but still timed out. Some people on the Internet said that it is because next-auth authentication requires access to github, but I have deployed a proxy locally and can curl github normally. I have also configured a global proxy. Is there any solution? Or is there a third party that supports NextAuth in mainland China? Or are there any other questions? Now I can log in with GitHub normally, but I can't make a callback. The container can ping baidu.com normally.
@Aspoir 这个报错是说明你的 github 请求访问失败,大概率是你的容器没法正常和 github 连通。尝试配置下代理的环境变量再试试。
✅ @Aspoir
This issue is closed, If you have any questions, you can comment and reply.
此问题已经关闭。如果您有任何问题,可以留言并回复。
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@Aspoir This error indicates that your github request failed, and it is likely that your container cannot connect to github normally. Try configuring the environment variables of the proxy under the try again.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.