Blocking specific routes based on user session
Hey, I was wondering what's the best approach to get user session and based on it prevent specific routes in website?
I though of doing that through middleware, however inside middlare I can't get session using this method:
As I it is not allowed to use Node’s dgram module in Edge runtime
What would be correct approach for this task?
8 Replies
you have to use fetch. middlewares aren't run directly in nodejs.
https://www.better-auth.com/docs/integrations/next#middleware
Next.js integration | Better Auth
Integrate Better Auth with Next.js.
this is true right now, but will change very soon
src: https://x.com/leeerob/status/1886547050134647070
I believe this change is already in canary version and can be enabled under the next config
experimental.nodeMiddleware
interesting
Its inside of next not vercel, correct me if im wrong
The pull for vercel is still open
https://github.com/vercel/vercel/pull/13028
GitHub
[next] Add node middleware handling by ijjk · Pull Request #13028 ·...
This adds the handling for nodejs runtime support for middleware added in vercel/next.js#75624
oooh got it