Integration of axum-gate with Leptos #4455
Unanswered
emirror-de
asked this question in
Q&A
Replies: 1 comment 2 replies
-
|
You can avoid the runtime error due to duplicate routes by adding the server function paths to the "excluded routes" list while generating routes. From the description, I'm a little unclear on whether you want all of the server function endpoints protected in the same way, or none of them, or some of them. The code below assumes you want all the server function endpoints protected, and only some of the application routes. let protected_routes = generate_route_list(ProtectedRoutesForRouteGeneration);
// get a list of all of the server function endpoint paths
let server_fn_paths = leptos::server_fn::axum::server_fn_paths()
.map(|(path, _)| path.to_string())
.collect::<Vec<_>>();
// when generating unprotected routes, explicitly *exclude* server fn paths so there are no duplicates
let unprotected_routes = generate_route_list_with_exclusions(
UnprotectedRoutesForRouteGeneration,
Some(server_fn_paths),
);
let app = Router::new()
// .leptos_routes(&leptos_options, routes, {
// let leptos_options = leptos_options.clone();
// move || shell(leptos_options.clone())
// })
.leptos_routes(&leptos_options, protected_routes, {
let leptos_options = leptos_options.clone();
move || shell(leptos_options.clone())
})
.layer(admin_gate)
.leptos_routes(&leptos_options, unprotected_routes, {
let leptos_options = leptos_options.clone();
move || shell(leptos_options.clone())
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to find an easy way to add route protection using axum-gate for a Leptos application, so I tried a few things to make this happen.
What already works pretty well is the recommended approach by using the
leptos_axum::extractfunction as described in the book at server functions. You can find my example here.However, I would love to get a possibility to protect the server functions or Leptos routes more convenient and without the boilerplate requirement on every server function. The boilerplate is always a possible failure in auth eg. by returning at the wrong point. What I am thinking of is a way to apply the
Gatelayer directly on the generated routes. I started trying it out, see the comments in this same example. I tried to split the routes into two components for the generation, see here. This attempt fails because Leptos is trying to add theuserserver function twice, because I am usingleptos_routestwice.It would be pretty nice to get a smooth solution for applying axum layer on parts of Leptos routes.
Questions:
Beta Was this translation helpful? Give feedback.
All reactions