Files
narlblog/backend/src/auth.rs

13 lines
424 B
Rust

use crate::error::AppError;
use axum::http::HeaderMap;
use tracing::warn;
pub fn check_auth(headers: &HeaderMap, admin_token: &str) -> Result<(), AppError> {
let auth_header = headers.get("Authorization").and_then(|h| h.to_str().ok());
if auth_header != Some(&format!("Bearer {}", admin_token)) {
warn!("Unauthorized access attempt detected");
return Err(AppError::Unauthorized);
}
Ok(())
}