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

[Bug] 使用clerk,预览知识库文件报错 Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() #6762

Open
dream-north opened this issue Mar 6, 2025 · 2 comments
Labels
🐛 Bug Something isn't working | 缺陷 files 上传文件/知识库

Comments

@dream-north
Copy link

📦 部署环境

Docker

📦 部署模式

服务端模式(lobe-chat-database 镜像)

📌 软件版本

1.67.2

💻 系统环境

Ubuntu

🌐 浏览器

Chrome

🐛 问题描述

使用自己构建的镜像部署(为了加入clerk相关环境变量)
测试环境的clerk没有问题,改为生产环境的clerk重新构建后,登录、问答、使用知识库都运行良好。
但是在知识库预览文件时报如下错误。

[rewrite] /files/file_PbbftBtd5DVU -> http://127.0.0.1:3210/zh-CN__0__light/files/file_PbbftBtd5DVU
 ⨯ Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware(). Please ensure the following:
- Your Middleware exists at ./middleware.(ts|js)
- clerkMiddleware() is used in your Next.js Middleware.
- Your Middleware matcher is configured to match this route or page.
- If you are using the src directory, make sure the Middleware file is inside of it.

For more details, see https://clerk.com/docs/quickstarts/nextjs

    at _ (.next/server/chunks/64630.js:11:4181)
    at <unknown> (.next/server/chunks/64630.js:1:3051)
    at async m (.next/server/chunks/58889.js:3:6174)
    at async d (.next/server/chunks/68336.js:1:3077)
    at async h (.next/server/app/[variants]/(main)/files/[id]/page.js:28:1254) {
  digest: '2881602596'
}

📷 复现步骤

自己构建docker镜像,通过docker-compose部署

在Dockerfile.database的第75行加入

ENV NEXT_PUBLIC_ENABLE_NEXT_AUTH=0 \
    NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_live_***" \
    CLERK_SECRET_KEY="sk_live_***" \
    CLERK_WEBHOOK_SECRET="whsec_****"

在知识库中预览文件

🚦 期望结果

No response

📝 补充信息

No response

@dream-north dream-north added the 🐛 Bug Something isn't working | 缺陷 label Mar 6, 2025
@github-project-automation github-project-automation bot moved this to Roadmap - Chat 1.x in Lobe Chat Routine Mar 6, 2025
@lobehubbot
Copy link
Member

👀 @dream-north

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 dosubot bot added the files 上传文件/知识库 label Mar 6, 2025
Copy link

dosubot bot commented Mar 6, 2025

Hey @dream-north! I'm here to help you with any bugs or questions you have. Let's get this sorted out together.

It seems like you're encountering an issue with Clerk authentication in a production environment when previewing files in the knowledge base. A similar issue was previously discussed, where the solution involved ensuring that the clerkMiddleware() is correctly implemented and used in your Next.js middleware setup. Here are some steps you can take to resolve this:

  1. Middleware Implementation: Ensure that the clerkMiddleware() function is implemented in the src/middleware.ts file. This function is crucial for handling authentication for protected routes [1].

  2. Middleware Usage: Verify that clerkMiddleware() is being used in your Next.js middleware configuration. This involves checking that your middleware file is correctly placed and that the middleware matcher is configured to match the routes or pages that require authentication, such as /files [1].

  3. Environment Variables: Double-check that all necessary environment variables are correctly set in your Dockerfile. This includes NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY, CLERK_SECRET_KEY, and any other relevant Clerk configuration.

  4. Docker Image: If you are using Docker, you might need to build the Docker image yourself with the correct environment variables. You can refer to a similar solution where a custom Dockerfile was used to include these variables [2].

By ensuring these configurations are correctly set up, you should be able to resolve the error related to Clerk 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

@dream-north dream-north changed the title [Bug] 使用clerk生产环境,预览知识库文件报错 Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() [Bug] 使用clerk,预览知识库文件报错 Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() Mar 11, 2025
@dream-north
Copy link
Author

直接预览文件没有问题,但是在加入知识库后,在知识库里预览就会报错

Image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working | 缺陷 files 上传文件/知识库
Projects
Status: Roadmap - Chat 1.x
Development

No branches or pull requests

2 participants