Session cookie not updating
I'm not totally sure what is going on. I augmented my session table to include my own organization data as well as the users timezone.
After a user is logged in, if they don't have an active organization, my middleware routes them to a page where they can choose an organization to use. When the user selects the organization an endpoint is called that updates the value in the session table.
I then call the
Once the server side call is done I run a
However, when I get the session in the middleware, using the recommended method with betterFetch, the session object does not have the active organization set nor does it have the timezone set, even if I use
My best guess is that there is some caching going on somewhere either in Next or in Better-Auth that is giving me an old cookie.
I need a fresh right-out-of-the-oven cookie!
Any help would be much appreciated.
Thanks!
After a user is logged in, if they don't have an active organization, my middleware routes them to a page where they can choose an organization to use. When the user selects the organization an endpoint is called that updates the value in the session table.
I then call the
getSession function with the disableCookieCache: true on the server. I saw in a Github issue that using that should refresh the cookie with the new data that is in the session table. When I log the results of that server side call to getSession it looks great. It's exactly as I expect with the active organization and the timezone set properly. Once the server side call is done I run a
getSession withe disableCookieCache on the client side as well, once again the session object looks great. I then use router.push to go to my dashboard. However, when I get the session in the middleware, using the recommended method with betterFetch, the session object does not have the active organization set nor does it have the timezone set, even if I use
disableCookieCache: true. I don't understand what is going on.My best guess is that there is some caching going on somewhere either in Next or in Better-Auth that is giving me an old cookie.
I need a fresh right-out-of-the-oven cookie!
Any help would be much appreciated.
Thanks!