lobehub / lobe-chat

🤯 Lobe Chat - an open-source, modern-design AI chat framework. Supports Multi AI Providers( OpenAI / Claude 3 / Gemini / Ollama / Azure / DeepSeek), Knowledge Base (file upload / knowledge management / RAG ), Multi-Modals (Vision/TTS) and plugin system. One-click FREE deployment of your private ChatGPT/ Claude application.
https://chat-preview.lobehub.com
Other
41.17k stars 9.37k forks source link

[Bug] UNAUTHORIZED error when visiting web ui #3825

Closed AbondonedScrawl closed 1 week ago

AbondonedScrawl commented 2 weeks ago

📦 Environment

Docker

📌 Version

Latest

💻 Operating System

Ubuntu

🌐 Browser

Chrome, Safari, Firefox

🐛 Bug Description

I have carefully followed each step in this guide https://lobehub.com/docs/self-hosting/server-database/docker-compose. Every time I end up with a chat that is not working. I get following error:

Screenshot 2024-09-08 at 15 33 49

When looking at lobe-database logs, it looks like this:

[Database] Start to migration...
✅ database migration pass.
-------------------------------------
  ▲ Next.js 14.2.8
  - Local:        http://localhost:3210
  - Network:      http://0.0.0.0:3210
 ✓ Starting...
 ✓ Ready in 51ms
next auth: undefined
2024/09/08 03:14PM 30 pid=1 hostname=41fb7efbb4b8 msg=Error in tRPC handler (lambda) on path: session.createSession, type: mutation
a [TRPCError]: UNAUTHORIZED
    at /app/.next/server/chunks/39184.js:1:2617
    at t (/app/.next/server/chunks/5663.js:1:5733)
    at r (/app/.next/server/chunks/5663.js:1:6075)
    at /app/.next/server/chunks/8946.js:1:7083
    at Array.map (<anonymous>)
    at y (/app/.next/server/chunks/8946.js:1:6644)
    at async E (/app/.next/server/app/trpc/lambda/[trpc]/route.js:1:3654)
    at async /app/node_modules/.pnpm/next@14.2.8_@babel+core@7.23.6_supports-color@8.1.1__@opentelemetry+api@1.9.0_react-dom@18.3._itjmu72s7n7tov6po6nkhcdpya/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36932
    at async eC.execute (/app/node_modules/.pnpm/next@14.2.8_@babel+core@7.23.6_supports-color@8.1.1__@opentelemetry+api@1.9.0_react-dom@18.3._itjmu72s7n7tov6po6nkhcdpya/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:27548)
    at async eC.handle (/app/node_modules/.pnpm/next@14.2.8_@babel+core@7.23.6_supports-color@8.1.1__@opentelemetry+api@1.9.0_react-dom@18.3._itjmu72s7n7tov6po6nkhcdpya/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:38186) {
  code: 'UNAUTHORIZED',
  [cause]: undefined

📷 Recurrence Steps

No response

🚦 Expected Behavior

No response

📝 Additional Information

Issue persists on other hardware as well.

lobehubbot commented 2 weeks ago

👀 @AbondonedScrawl

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。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

dosubot[bot] commented 2 weeks ago

Hey @AbondonedScrawl! I'm here to help with any bugs, questions, or contributions you have. Let's tackle this issue together!

I found a similar unsolved discussion: Using Auth0 for Deploying Server Database Version Using Docker [1]. Additionally, there are two closed issues that might be relevant:

  1. [Bug] docker部署时next-auth不可用 - The suggested solution is to configure the NEXTAUTH_URL variable as per the documentation [2].
  2. [Bug] OAuth throw trusthost error on Docker deployment - This issue was resolved by a pull request: :bug: fix: fix OAuth errors on Docker deployment [3].

To resolve the "UNAUTHORIZED" error when visiting the web UI in a Docker environment on Ubuntu, follow these steps:

  1. Check Environment Variables: Ensure that the environment variables related to authentication are correctly set in your .env file. Specifically, verify the following variables:

    NEXT_AUTH_SECRET=3904039cd41ea1bdf6c93db0db96e250
    NEXT_AUTH_SSO_PROVIDERS=auth0
    NEXTAUTH_URL=http://localhost:3210/api/auth
    AUTH0_CLIENT_ID=xxxxxx
    AUTH0_CLIENT_SECRET=cSX_xxxxx
    AUTH0_ISSUER=https://lobe-chat-demo.us.auth0.com
  2. Restart the LobeChat Service: After making sure the environment variables are correctly set, restart the LobeChat service to apply the changes:

    docker compose up -d
  3. Check CORS Configuration: Ensure that CORS settings are correctly configured to allow cross-origin requests. This can be done in the MinIO WebUI or through Docker Compose environment variables:

    MINIO_API_CORS_ALLOW_ORIGIN=http://localhost:3210
  4. Verify Authentication Service: Make sure the authentication service (Auth0 in this case) is running and accessible. You can check the logs for the Auth0 container to ensure it is running without errors:

    docker logs -f lobe-auth0

By following these steps, you should be able to resolve the "UNAUTHORIZED" error when accessing the web UI [4][5].

To continue talking to Dosu, mention @dosu.

arvinxx commented 2 weeks ago

Do you login?

AbondonedScrawl commented 2 weeks ago

Do you login?

Not sure what you mean. I just follow the guide

arvinxx commented 1 week ago

I mean you need to login and then try the upload

AbondonedScrawl commented 1 week ago

Damn it, I missed that part completely. Thank you. Now it is working

lobehubbot commented 1 week ago

✅ @AbondonedScrawl

This issue is closed, If you have any questions, you can comment and reply.\ 此问题已经关闭。如果您有任何问题,可以留言并回复。

moeinrahimi1 commented 15 hours ago

I have followed instruction using docker-compose, after configuring logto and updating env, lobe chat wont show me login page but rather every action result in unauthorized

arvinxx commented 11 hours ago

@moeinrahimi1 click the logo to login