-
Over the weekend I was setting up a leptos project with user auth, and just got that working. I figured some routes, like admin panels, should be protected, but I can't see how to use the I made a server function that returns an Option and set up a resource that would call the function and return true/false depending on the state of the user enum. I then used this resource in the So, my question is, how are protected routes supposed to be used? Is there a way to call the server function in the component only during SSR? That way the logged in user can directly navigate to the dashboard without being redirected away? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
ProtectedRoute does not work well with async/resources because it only checks the condition once, IIRC. I'd suggest using regular routes, and wrapping the route Outlet in a Suspense that checks the resource and shows the Outlet or not, as in this example: https://book.leptos.dev/router/16_routes.html#conditional-routes |
Beta Was this translation helpful? Give feedback.
ProtectedRoute does not work well with async/resources because it only checks the condition once, IIRC. I'd suggest using regular routes, and wrapping the route Outlet in a Suspense that checks the resource and shows the Outlet or not, as in this example: https://book.leptos.dev/router/16_routes.html#conditional-routes