use axum::extract::State;
use axum::http::HeaderMap;
use axum::response::IntoResponse;
use super::super::auth::{ApiError, AppState, resolve_auth};
pub async fn create_session(
headers: HeaderMap,
State(state): State<AppState>,
) -> Result<impl IntoResponse, ApiError> {
let (_identity, auth_ctx) = resolve_auth(&headers, &state, "http")?;
let handle = state.shared.session_handles.create(auth_ctx);
Ok(axum::Json(serde_json::json!({
"session_id": handle,
"expires_in": 3600,
})))
}
pub async fn delete_session(
headers: HeaderMap,
State(state): State<AppState>,
) -> Result<impl IntoResponse, ApiError> {
let handle = headers
.get("x-session-id")
.and_then(|v| v.to_str().ok())
.ok_or_else(|| ApiError::BadRequest("missing X-Session-Id header".into()))?;
let found = state.shared.session_handles.invalidate(handle);
if !found {
return Err(ApiError::BadRequest("session handle not found".into()));
}
Ok(axum::Json(serde_json::json!({ "status": "ok" })))
}