How to refresh user/session data?
I'm having a hard time figuring out how to refresh the user/session data after the field values in the user schema gets updated.
Scenario: When setting the
email_verified to true/false in the database, the user object returned from still contains the old value of this field, making it confusing for the user to see if their email verification worked or not. The only way to update this is for the use to log out and back in, which isn't ideal of course.18 Replies
Do you use cookie cache?
I don't
I do use redis as my secondary storage
Oh, it might be the issue
Looks like that's indeed the issue
Is there a way to tell better-auth to save sessions exclusively in the database and use the redis storage only for rate limits?
Bump
how are they logging in if they aren't verified? that should not work
because i do not require them to verify their email on signup
if you do it would fix this issue
you could also fetch the session like this, which should force update the session for you.
It will not, as they can change their email in their settings, which will update the
email_verified column to FALSE, but not be represented in the UI as the session isn't being updated.
Besides, the issue is that the session isn't being updated when using secondary-storage, causing any updates to the user info to be not updated instantly, and there is no option to disable sessions being stored in the secondary storage.
I do not have cookie caching enabled in the first placeOptimizing for Performance | Better Auth
A guide to optimizing your Better Auth application for performance.
sure, but that is another layer which was not apart of the original issue.
i'm also using secondary storage, and my sessions are up-to-date upon refresh
what version are you on?
i'm also using secondary storage, and my sessions are up-to-date upon refreshthat's interesting 1.3.27
let me try that version now
to further clarify, i'm in a turborepo project with a next.js web app. and i'm using the prisma adapter for better-auth.
might be a version thing, lets find out, hold on
might be a framework thing
maybe
as I'm using sveltekit with drizzle
yeah maybe
this is my better-auth config
i don't see why this would affect session freshness. might be worth raising a github issue for this
for what its worth i tried version
1.3.27 with no issue. so its not a version issue, at least in my environment