backend/config/auth/
middleware.rsuse actix_http::HttpMessage;
use actix_web::dev::ServiceRequest;
use actix_web_grants::permissions::AttachPermissions;
use actix_web_httpauth::extractors::bearer::BearerAuth;
use super::{claims::Claims, user_info::UserInfo};
pub fn validator(
req: ServiceRequest,
credentials: &BearerAuth,
) -> Result<ServiceRequest, (actix_web::Error, ServiceRequest)> {
let user_info = match Claims::validate(credentials.token()) {
Ok(claims) => UserInfo::from(claims),
Err(err) => return Err((err.into(), req)),
};
req.extensions_mut().insert(user_info.clone());
req.attach(user_info.scopes);
Ok(req)
}