Middleware is ok for authentication (checking who a user is), but not for authorization (checking if a user is allowed to do something) which is what you’re looking at here
You should check this manually in every server function before you perform the action.
Thanks for response. But like I said in that post I do check in server function but problem is that server function is never invoked due to “redirect” in middleware. Instead server function just returns undefined (see this one too).
That makes more sense! That solution was from gh issue I linked but initially i thought it was based on checking “api” in routes - and thought it would not work. It seems it checks header.
I will verify if it works tomorrow.
It would be nice to add this info in Nextjs docs don’t you think? Especially like I said lots of guides (even from vercel team) use middleware for authentication/authorization afaik.