Session Caching with Custom Fields Workaround
I've been using Next Auth and was thinking to switch over, however the line below is making me hesitate. I do not want to hit the db on every request, but I also want to use custom fields such as roles. Is there an alternative or work around for this?
7 Replies
Is using
additionalFields
a viable option here? Would those fields be cached?what was your usecase for caching may be i can navigate you around ?
With Next Auth I used short lived JWTs with a table to refresh them so it hit the db every now and then. Better auth uses sessions which I'm ok with but I don't want to hit the db every request.
The project I intend to use with better auth is new so not sure what I may need just yet, besides role(s). If I can extend the user and session objects with additionalFields and still use the cookie cache that's fine with me.
all additional fields will be cached. Only the callback you pass on custom session will be called
Did some more reading, is it that additional fields is used to extend the better auth session response but custom session is used to (potentially) overwrite it in a sense?
custom session is if you want additional information like querying additional db
both session & user table data are cached
Hmm...I use the table inheritance pattern where user table is the base and the roles share a primary key with the user table. Seems like I would have to use the custom session plugin here, which means no caching