Clerk auth session not working in production

132 views Asked by At

In my production Next.js application using Clerk for authentication, I am unable to access my authenticated session, even though the user is successfully created in Clerk and even successfully synced to my database using a webhook.

It works in localhost but in my server-side logs, I see this error

⨯ node_modules/@clerk/nextjs/dist/esm/server/createGetAuth.js (26:12) @ eval ⨯ Error: Clerk: auth() was called but Clerk can't detect usage of authMiddleware(). Please ensure the following:

  • authMiddleware() 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.

I am not using /src and I have my middleware.ts file in the root directory of my project, alongside the app directory. I am also running on Node v21.7.1.

This is my middleware.ts:

import { authMiddleware } from "@clerk/nextjs";
 
export default authMiddleware({
    publicRoutes: ["/", "/sign-in", "/sign-up", "/api/webhooks(.*)", "/api/send(.*)", "/api/notification-test", "/api/upload-set(.*)"],
});
 
export const config = {
  matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/"],
};

In the browser console of my production application, I see this error:

clerk.browser.js:2

   POST https://clerk.mentis.chat/v1/client/sessions/sess_2duNOvIGQw4G5uEhJYncTlEKuc3/tokens?_clerk_js_version=4.70.5 404 (Not Found)
0

There are 0 answers