server_middleware/extract/
auth.rs1use std::sync::Arc;
2
3use axum::{extract::FromRequestParts, http::request::Parts};
4use server_common::{error::auth::AuthError, jwt::Claims};
5
6pub struct Auth(pub Arc<Claims>);
7
8impl<S> FromRequestParts<S> for Auth
11where
12 S: Send + Sync,
13{
14 type Rejection = AuthError;
15
16 async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
17 let claims = parts
18 .extensions
19 .get::<Arc<Claims>>()
20 .ok_or(AuthError::MissingToken)?;
21 let auth_info = Auth(claims.clone());
23 Ok(auth_info)
24 }
25}