Middleware not redirecting server function invocations #81608
-
I stumbled this situation in Nextjs App router. I have middleware which inside has following code:
This normally works e.g. when navigating from URL. Now, when I arrive at the above middleware when a server function is invoked, the redirect does not happen (although it enters inside
Is this normal behavior? What options do I have in such situation? Checking session in server function won't change anything here because like I said server function does not get invoked due to middleware. This is related. I think they suggest there to not handle the server functions in middleware, but then question comes, how to know from middleware if this is a server function or not? IMHO server functions don't start with "api" to check that as one user suggested. EDIT: it seems in above link the suggestion checks header instead of "api" to bypass server functions in middleware. I will verify that solution when I get to PC and close this if that works. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It seems answer is this (from the gh link I mentioned):
Somehow I thought initially it was using "api" check to exclude server functions from middleware but I was wrong. |
Beta Was this translation helpful? Give feedback.
It seems answer is this (from the gh link I mentioned):
Somehow I thought initially it was using "api" check to exclude server functions from middleware but I was wrong.