better-auth-ui & Tanstack Start query issue
@daveycodez I'm trying to setup better-auth-ui with tanstack start and tanstack query. 
I followed exactly whats on the docs and the issue is when i log in and it re-directs me to "/" which i set in the 
redirectTo="/" of AuthView, using the tanstack query devtools the ["session"] data is always null. if i have the redirectTo="/dashboard" set, then it does have the data. So something to do with the home page that it resets the data to null. any idea? Thank you42 Replies
here is the project, please let me know if you have any idea. thank you
GitHub
GitHub - Anonymous2416/test2
Contribute to Anonymous2416/test2 development by creating an account on GitHub.
providers.tsx is in src/lib/providers.tsxare you using authClient.useSession to get the session
no, im not using that anywhere
That might be why
I'm not sure exactly how you are getting session in TanStack but you should be receiving a new session via authClient.useSession after sign in
but i thought better-auth-ui with better-auth-tanstack does all of this automatically? or no?
im using these
mb, i thought i specified i was using 
better-auth-tanstack but i didnt. sorryAnd you're using the AuthUIProviderTanstack?
Hmm this is weird I'm looking at the code and I can't identify an issue
yea
yea idk whats happening
after you sign in what happens if you go to /api/auth/get-session
i get the session correctly with all the values
Where are you not getting the session exactly then
also when the 
"/" page loads, it prints this in the server log too tried to stream query ["session"] after stream was already closed
in the home page /Like in SSR?
after logging in and i put it to redirect to 
/I don't see where you're trying to log this
If you put useSession() from better-auth-tanstack in your / page you should be able to get the session just fine
Oh you mean in TS Query the data isn't present
Do you see a fetch to get-session after you sign in in chrome network tab
yes
Or if you refresh the page on "/" does it fix it
also jus tried doing ths in 
__root.tsx in RootDocument and it gives error
Yea cause that has to go inside of Providers
AuthUIContext is null outside of the Providers scope
Maybe you need to put your TanstackDevTools inside of Providers
Cause it needs access to the QueryClient
I would even move those devtools directly into providers.tsx
as a child of AuthQueryProvider
same error? 
useSession has to be a child of providers
if you do it before you render your QueryProvider it won't work
You're trying to access the context before it is initialized
oh true mb, let me do it in index, lets see now
that could be it, let me try,. 1 sec
It likely is the issue since TanstackDevTools probably does "useQueryClient" and if it's outside of providers your queryclient will be null
same issue 🙁
i did log in 
index.tsx and it does get it, but then its null.
and this keeps logging in server logs

It looks like you’re trying to read the session in server context but in the client idk
I need to make a new example for the latest TanStack start anyway. Maybe when I’m done with my current project.
But if you keep all your Auth client side it should work for now
Like React hooks only
thats the thing though im only accessing the context here, im not doing anything else anywhere just what better-auth-tanstack does behind the scenes https://github.com/Anonymous2416/test2/blob/main/src/routes/index.tsx#L11
GitHub
test2/src/routes/index.tsx at main · Anonymous2416/test2
Contribute to Anonymous2416/test2 development by creating an account on GitHub.
alright please let me know, thank you 🙏
i still havent updated to the new RC version. im on 
1.131.50
@daveycodez hey sorry to bother you about this, its just been really frustrating. do you have an example project i can clone with tanstack start (im using version 1.131.50) i can try out to see if it works or if something wrong im doing on my partIt hasn't been updated in a while
https://github.com/daveyplate/better-auth-tanstack-starter
after some testing around the problem has something to do with where/when im creating the 
QueryClient and where/when im importing to use it
thats what causes the tried to stream query ["session"] after stream was already closed message and issue with data being null in the query
@daveycodez hey i managed to get things working. I had a question regarding prefetching in beforeLoad, what does it provide so i can make it work, since beforeLoad runs on both server and client. Im trying to avoid the flickering/wrong ui showing of the user avatar button on page loadkinda like in the demo, a flicker happens of the user avatar https://newtech.dev/auth/sign-in
You likely want to show a loader skeleton
im trying to prefetch like this
but it gives this error:
was able to get it working by doing this. not sure if this is the right approach or what you recommend, but it worked
Honestly I have no idea I'm a TanStack start noob but I'm glad that's working
I mainly use Next.js but I do want to update everything to work very cleanly with TanStack Start, but it changed a lot since my initial integrations so I've been waiting for it to stablize before diving into any significant updates there
End goal is to have everything perfected across the board for Next.js / TSS / RR7 along with simple demos
thats great to hear, thank you for everything you do!
@daveycodez hey sorry to bother you again, when using the 
UserButton component, when it tries to load the avatar image that it got from signing in with google, it shows this in the network requests, you know what could be causing this?
You might see this in dev sometimes
It's Google rate limiting