TanStackT
TanStack8mo ago
3 replies
urgent-maroon

Auth - Supabase - Protected Routes - Tanstack Query

Im wondering if i could get some help understand all of this and how it all comes/works together.

So i looked at this video:
https://www.youtube.com/watch?v=6c8kuvBolQg&t=7s&ab_channel=DevLeonardo
repo: https://github.com/Balastrong/confhub/tree/dc79c9f8fd2a4fb621e2b7029bb0e8dd202d6eb6

i was playing around with some of the code in my own project. If you use ensureQueryData in the root and then in your profile route you delete the cookies for the session in the browser dev tools, then go /home then back to /profile it will let you go to /profile even though you dont have the cookies. When using fetchQuery in root route, it does fix this issue, but then it makes (authQueries) 1 network request when going from /profile to /home and 2 networks requests when going from /home to /profile.

You can try out what im talking about here: https://tanstarter.nize.ph/
repo: https://github.com/dotnize/react-tanstarter
it uses the same concept.

Im just trying to understand how all these things come together. The authenticated/protected routes with tanstack query. Different staleTimes for the session? etc..

I would really appreciate it. Thank you so much!
Was this page helpful?