refetch() from useSession() return cached data
Why does calling
refetch()
from useSession()
return cached data? This only happens in production. The updated data is returned after approximately 50 seconds. In development, it always returns fresh data immediately after calling refetch()
12 Replies
client code:
server code:
Sorry, can somebody help me?, it s been days, i need a clue for this issue @bekacru @Ping thank you
are you using cookie cache?
you should use
authClient.updateUser
instead of calling the server method. This wil handle refetching the session itselfi mean i have a lot of server logic on the server such as, saving profile picture on the api folder, change password, etc. i couldn't do that stuff on client. what do you think?
oh my repo is not updated yet, i have account page for updating user profile and info here
i did something like this on the server (i'm not using better-auth api to update the user)
why this caching issue only happens in production?
the
refetch
from useSession
updates the user info, but only in devrefetch from useSession should work. But the other option you can try is use
authClient.getSession
with react queryi did try that too, wrapping getSession with react-query also has the same caching issue (only in production)
them the caching is happening on the server side
make sure api routes are fully dynamic and awlays return fresh data
i will try to fix thiss issue again, like in 3 hours from now. i'll give you an update later
@bekacru i have trying to console.log every route in my server, it always showing updated data, but the
useSession
in client always returns cache data for like ~50 seconds.
here is my updated repo:
https://github.com/mamlzy/orpc-experiment
GitHub
GitHub - mamlzy/orpc-experiment
Contribute to mamlzy/orpc-experiment development by creating an account on GitHub.
Oh even with
authClient.updateUser
still caching in production, what happened here, is it only in my side or in better-auth, im pretty confused here
I have fixed the issue, its all about my caching things on my vps 😔 sorry for bothering you @bekacru, thank you for helping me!
