Next.js middleware handler is not a function
Unanswered
Clumber Spaniel posted this in #help-forum
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
also i think first if statement wont run, matcher only has home, sign-in, sign-up and error, not api/auth route on it
@chisto 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
Clumber SpanielOP
its in
src/
dir, which is what you meant right?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
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
@chisto 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
Clumber SpanielOP
i use better auth in middleware - so now it causes
The edge runtime does not support Node.js 'crypto' module.
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
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
I think the nodejs runtime is still experimental and some libraries aren't ready yet, better do it the old way
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?
from middleware