How to handle authentication (get session data)
My knowledge on this has atrophied. 😩
With NextJS I'm so used to having async as the default. Now that I'm with Tanstack Router this isn't the case (as of now). I'm struggling how to use
Imagine I have the following:
Now that
AssetContainer
needs to be async due to the await. Does each parent function now needs async, until I go up the chain to the Route?
I've tried using use
with React 19 but unfortunately this doesn't work.
How should I approach this? Looking for best practice.
Note: I did check the docs to see if there was a way of passing down data from the Router to the top level component and didn't see this was the case.3 Replies
manual-pinkOP•9mo ago
I decided to make the
AssetContainer
function async.
I then wrapped it in the parent component within suspense.
It works but now I get:
Am I approaching this the wrong way? Should I be using Start
instead?
https://github.com/TanStack/router/blob/main/examples/react/authenticated-routes/src/auth.tsx#L16-L26
I see the use of localStorage employed. So I decided to use this instead.
In the top level entry point of the app.quickest-silver•9mo ago
The example you showed in the OP seems like a server component. These are not yet supported in TanStack Start (which will eventually support them). For now you can use React Query useQuery hook + TanStack Start queryClient.ensureQueryData to simulate it.
manual-pinkOP•9mo ago
The example you showed in the OP seems like a server component.Very True. I'm trying to kick the old NextJS habit of the past 4+ years 😂 and trying to relearn new patterns.
For now you can use React Query useQueryI'm wanting to avoid an over-reliance on that. As I'm going to be using either
zero/electric-sql/jazz-tools
or some other mechanism for interface with the database.