axum_login/
extract.rs

1use axum::{
2    extract::FromRequestParts,
3    http::{request::Parts, StatusCode},
4};
5
6use crate::{AuthSession, AuthnBackend};
7
8impl<S, Backend> FromRequestParts<S> for AuthSession<Backend>
9where
10    S: Send + Sync,
11    Backend: AuthnBackend + Send + Sync + 'static,
12{
13    type Rejection = (StatusCode, &'static str);
14
15    async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
16        parts.extensions.get::<AuthSession<_>>().cloned().ok_or((
17            StatusCode::INTERNAL_SERVER_ERROR,
18            "Can't extract auth session. Is `AuthManagerLayer` enabled?",
19        ))
20    }
21}