Use Cache Directive with getSession

for anyone using getSession in nextjs, and not using cookieCache for the sessions but instead the 'use cache' directive, be aware that calling await headers() like this will make caching not work since headers are non-serializable, @bekacru any workaround here? Maybe only passing the authorization header in the getSession parameter? doing await headers() inside the api.getSession will not be allowed with the use cache directive, so it has to be outside of the functions scope
No description
4 Replies
deved9036
deved9036OP5d ago
I've also tried just directly passing down the better-auth.session_token, this doesn't work either
No description
lonelyplanet
lonelyplanet4d ago
could you use await auth.$context and use context methods to get session rather than using the endpoint
lonelyplanet
lonelyplanet4d ago
GitHub
better-auth/packages/better-auth/src/api/routes/session.ts at dca7f...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
lonelyplanet
lonelyplanet4d ago
GitHub
better-auth/packages/better-auth/src/api/routes/session.ts at dca7f...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth

Did you find this page helpful?