web admin panel working well

This commit is contained in:
Priec
2026-07-16 13:25:28 +02:00
parent 3540c028e9
commit d2ac592a49
45 changed files with 2578 additions and 30 deletions

View File

@@ -0,0 +1,21 @@
use axum::http::HeaderMap;
use tonic::{Request, metadata::MetadataValue};
#[derive(Debug)]
pub(crate) enum AuthenticationError {
Missing,
Invalid,
}
pub(crate) fn authenticated_request<T>(
headers: &HeaderMap,
message: T,
) -> Result<Request<T>, AuthenticationError> {
let token = crate::cookie_value(headers, "analytics_token")
.ok_or(AuthenticationError::Missing)?;
let value = MetadataValue::try_from(format!("Bearer {token}"))
.map_err(|_| AuthenticationError::Invalid)?;
let mut request = Request::new(message);
request.metadata_mut().insert("authorization", value);
Ok(request)
}