Expand description
RequireRole<A, R> for actix-web (feature actix): lets a route through only for a role.
use actix_web::web;
use fastauth_core::prelude::*;
use fastauth_plugin_admin::actix::RequireRole;
use fastauth_plugin_admin::{Admin, role};
type AppAuth = Auth<MemoryAdapter, (), plugins![Admin]>;
role!(pub Support = "support");
async fn dashboard(admin: RequireRole<AppAuth, role::Admin>) -> String {
format!("hello {}", admin.user.email)
}
async fn tickets(agent: RequireRole<AppAuth, Support>) -> String {
agent.user.name.clone()
}
fn routes(config: &mut web::ServiceConfig) {
config
.route("/admin", web::get().to(dashboard))
.route("/tickets", web::get().to(tickets));
}Structsยง
- Require
Role - The signed-in session of a user who holds role
R. Rejects with401 UNAUTHORIZEDwithout a session and403 FORBIDDENwithout the role, like the axumRequireRole. Derefs to theSession.