aleksa
aleksa
BABetter Auth
Created by aleksa on 4/24/2025 in #help
How to invalidate the cookie cache after successful purchase via Polar?
Hello everyone, if some could please help me. I have auth already implemented and use additionalFields for the balance of the users, the problem is when the user buys more credits via Polar and gets redirected to the /success page in the Navbar where I display the balance I still see the cached value that comes from getSession but in the Databse I can see the updated value. I managed to remove the cookie with something like this:
const removeCookie = createServerFn({ method: 'GET' }).handler(async () => {
// invalidate better-auth.session_data cookie
setCookie('better-auth.session_data', '', {
maxAge: -1,
});
});
const removeCookie = createServerFn({ method: 'GET' }).handler(async () => {
// invalidate better-auth.session_data cookie
setCookie('better-auth.session_data', '', {
maxAge: -1,
});
});
but then the better-auth.session_data cookie is compeletly gone and I don't know how to regenerate it, if that makes sense, or is there a better way to do this? I found a similar idea mentioned here: https://discord.com/channels/1288403910284935179/1288403910284935182/1336409002824826943 I need the value in Navbar that comes from the session to get updated after the webhook gets triggered and the DB gets updated, but still use cookieCache without disableCookieCache: true for the getSession.
2 replies