Thoughts on using an authentication function? #160
Unanswered
jhjacobs81
asked this question in
Q&A
Replies: 2 comments
-
You don't need to use IF/ELESE to do this. You should use middleware. This middleware will effect all nested routers. Router::with_hoop(check_authed).push(Router:with_path(...)...).push....
#[handler]
async fn check_authed(res: &mut Response, ctrl: &mut FlowCtrl) {
if authed {
pass
} else {
res.set_error_code(....);
ctrl.skip_next();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
i surely keep you busy :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So, this is not specificly a salvo question, but since this is a discussion platform i'm hoping its allowed to stay :-)
I am learning Rust, and as a first project im trying to create a web portal with Salvo. And i wonder which direction to go in regards to user authentication. Ofcourse i can do an IF/ELSE statement in each handler, but perhaps its better to form it into a function? A nicety would be user roles, like "User jhjacobs81 is administrator" and then on pages from the /admin/ path they need to login and have the role administrator. Since i now have sessions working this could then easily added to a session. But im not sure how i would do this best.
Beta Was this translation helpful? Give feedback.
All reactions