potree_auth/user/http/
extractors.rs1use axum::extract::FromRequestParts;
2use http::request::Parts;
3use tower_sessions::Session;
4
5use super::super::domain::User;
6use crate::common::utils::http::api_error::ApiError;
7
8pub const USER_SESSION_KEY: &str = "user_session";
10
11pub struct UserExtractor(pub Option<User>);
12
13impl<S> FromRequestParts<S> for UserExtractor
17where
18 S: Send + Sync,
19{
20 type Rejection = ApiError;
21
22 async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
23 let session = Session::from_request_parts(parts, state).await.map_err(|_err| ApiError::ServerConfiguration{message:"could not find tower sessions in request - ensure that tower sessions is in the middleware stack".to_owned()})?;
24 let user = session.get::<User>(USER_SESSION_KEY).await.unwrap();
25
26 Ok(Self(user))
27 }
28}