Trying to understand the connection between client and server in Tanstack Start
I've been exploring/experimenting with Tanstack Start framework. I mostly have the auth working, however I'm trying to understand why the
useSession
hook is not working as expected (will not update when authentication happens, will update when logging out with the auth client).
Is there something I was supposed to do to connect the auth client with auth server (-side implementation)? Doc's seem to just indicate it should just work as-is.5 Replies
You mean when logging in or state change ... useSession is not triggered ? Or when logging in , you are not seeing any session update ? .. can you clear out what is actually happening ?
Yes when logging in, I redirect back to my index-root route. There on that route, there is two components utilizing the
useSession
hook, and neither will update with session data.Same issue, redirecting to / where
useSession
hook is used to display user information in the header component, but console.log
returns the following:
data: null
error: null
isPending: false
isRefetching: false
Doesn't seem to be caching issue, but I am not sure. This works only when I refresh the page
Okay I think I figured it out. This happens when you define auth client twice. So if you already have a
auth-client.ts
file which exports an instance and you create a new one somewhere in components like i did in the screenshot in my previous message, it causes some kind of collision. Instead just import the existing one like in this screenshot
Yeah I didn't do that
I'm using a single instance like shown in the getting started guide