Clerk: auth() was called but it looks like you aren't using authMiddleware in your middleware file
I'm using the nextjs app dir, and my middleware is definitely being called:
But I still get the error that I'm not using authMiddleware when I use
Any suggestions?
11 Replies
this is my file structure
Im actually having the same issue as OP. And my file structure follows fasm's. I tried wrapping the console log in an annonymous function, no luck.
Strange, I have a similar setup. Altough, I'm using
getAuth()
instead of auth()
on the server:
import { getAuth } from '@clerk/nextjs/server';
And const auth = useAuth();
on the client. Where do you actually call auth()
?Try moving the middleware file outside the src folder
I spent ages on this, and ended up fixing it by updating my version of node to v20
apologies for the noob question, but how do you go about doing that? Do I need to update the node version globally or just from within my repo?
I used nvm, see here https://www.freecodecamp.org/news/how-to-update-node-and-npm-to-the-latest-version/
freeCodeCamp.org
How to Update Node and NPM to the Latest Version
Node is a runtime environment that allows developers to execute JavaScript code outside the browser, on the server-side. NPM, on the other hand, is a package manager for publishing JavaScript packages (also known as Node modules) to the npm registry [https://www.npmjs.com/]. You can also use it to install packages to
and you upgrade it globally
Had this issue just now.
What worked was:
- Moving the king
middleware.ts
to the root of the src
folder - alongside app
.
- Upgrading to Node.js 20 - I did this with nvm
since I'm lucky enough to be on Linux
- Removing publicRoutes was necessary for the first time running but I'm not certain this had any effectBtw nvm is available on windows fnm to :p
Aah yeah but i had to look for a package called nvm-windows once. Keep in mind its a separate package. Come as an MSI i believe though