Provide context before rendering? #1701
-
Hello, In my application, I set user authentication with cookies that are HTTP only. I use a My problem is that I use this signal in my To add some difficulties, I use hydratation of course. So I don't want my server nor my client to run the router before the authentication is checked (by a server function as the cookie is HTTP only). Does anyone have this use case and found a solution? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Correct me if I'm wrong but it seems In use with a nested |
Beta Was this translation helpful? Give feedback.
There's a distinction between "defining the routes" and "rendering the routes." You do want all your routes to be defined unconditionally, you don't want your routes to be rendered in response to a request unconditionally. If the authentication state is stored in a signal, then a
Show
or conditional around anOutlet
should work. If the authentication state is stored in a resource, thenSuspense
around anOutlet
.I don't think there's any reason this needs to be a local resource but of course I could be wrong. If you use plain
create_blocking_resource
and read it in aSuspense
that renders either theOutlet
or aRedirect
, you should be fine. Note that it needs to be a blocking resource for…