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:
const session = await auth.api.getSession({
headers: await headers() // you need to pass the headers object.
})
const session = await auth.api.getSession({
headers: await headers() // you need to pass the headers object.
})
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
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Aoki
Aoki2w ago
this is true right now, but will change very soon src: https://x.com/leeerob/status/1886547050134647070
lonelyplanet
lonelyplanet2w ago
I believe this change is already in canary version and can be enabled under the next config experimental.nodeMiddleware
Aoki
Aoki2w ago
interesting
lonelyplanet
lonelyplanet2w ago
Its inside of next not vercel, correct me if im wrong
lonelyplanet
lonelyplanet2w ago
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
Aoki
Aoki2w ago
oooh got it

Did you find this page helpful?