How to Efficiently Cache JWT in Next.js to Avoid 1.5s Latency?
Hey everyone — I'm using BetterAuth with Next.js and running into an issue where fetching the session and JWT (on the server) adds ~1.5 seconds of latency to every request.
I'd love to know if anyone has a reliable and secure pattern to persist the JWT on the server that avoids hitting the auth endpoint every time.
I've already tried storing the JWT in cookies, but it doesn't work reliably because the session changes when switching organizations — I'm using BetterAuth's organization system.
Any insights or working strategies would be hugely appreciated 🙏
Thanks in advance!
4 Replies
Just curious, any reason you need to use JWT over our traditional session based systems?
Because I'm making an organization system, the goal being to have a database per organization, so I use APIs and to authenticate securely the jwt is a good solution 🙂
up for JWT, for my case i don't want to store session in DB
Finally i've created my own jwt