Skip to main content

Module actix

Module actix 

Source
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ยง

RequireRole
The signed-in session of a user who holds role R. Rejects with 401 UNAUTHORIZED without a session and 403 FORBIDDEN without the role, like the axum RequireRole. Derefs to the Session.