Next.js Discord

Discord Forum

Next.js middleware handler is not a function

Unanswered
Clumber Spaniel posted this in #help-forum
Open in Discord
Clumber SpanielOP
any idea what is this error about?

11 Replies

Clumber SpanielOP
this is my middleware...
i use next@15.4.0-canary.67
is the middleware at the root folder? if yes then try removing nodejs runtime
also i think first if statement wont run, matcher only has home, sign-in, sign-up and error, not api/auth route on it
yes, I was reading this post
https://community.vercel.com/t/middlewarehandler-is-not-a-function/8757
and some solutions were someone who had it on app folder instead of src
or removing nodejs runtime for now as workaround until they fix it
seems like a new bug
ah sorry, didn't know you were using better auth
have you tried using getSessionCookie from "better-auth/cookies" ? since you don't need the full session object
I haven't use better auth but that's on their docs

In Next.js middleware, it's recommended to only check for the existence of a session cookie to handle redirection. To avoid blocking requests by making API or database calls.

You can use the getSessionCookie helper from Better Auth for this purpose

I think the nodejs runtime is still experimental and some libraries aren't ready yet, better do it the old way
did you have nodeMiddleware:true on your next config when u had runtime nodejs?