summaryrefslogblamecommitdiff
path: root/src/extractors.rs
blob: 4d441e94c0722ee4da88c7a47596f6955041bfb6 (plain) (tree)























                                                                 
use axum::{
    extract::{Request, State},
    http::{HeaderMap, StatusCode},
    middleware::Next,
    response::Response,
};

use crate::AppState;

pub async fn auth(
    State(state): State<AppState>,
    headers: HeaderMap,
    request: Request,
    next: Next,
) -> Result<Response, StatusCode> {
    let secret = headers.get("authorization");
    match secret {
        Some(token) if token == state.config.apikey.as_str() => {
            let response = next.run(request).await;
            Ok(response)
        }
        _ => Err(StatusCode::UNAUTHORIZED),
    }
}