refactor
This commit is contained in:
12
backend/src/auth.rs
Normal file
12
backend/src/auth.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use axum::http::HeaderMap;
|
||||
use tracing::warn;
|
||||
use crate::error::AppError;
|
||||
|
||||
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(())
|
||||
}
|
||||
Reference in New Issue
Block a user