Revert "feat(auth): refactor token resolution into shared TokenResolution and centralize in middleware; simplify AuthenticatedClient to carry resolved DB ID"
Some checks failed
CI / Check (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Formatting (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Release Build (push) Has been cancelled

This reverts commit 5ddf284b8f.
This commit is contained in:
2026-03-05 19:53:50 +00:00
parent 5ddf284b8f
commit 90ef026c96
4 changed files with 3 additions and 132 deletions

View File

@@ -305,6 +305,7 @@ pub mod middleware {
middleware::Next,
response::Response,
};
use sqlx;
/// Rate limiting middleware
pub async fn rate_limit_middleware(
@@ -315,20 +316,12 @@ pub mod middleware {
// Extract token synchronously from headers (avoids holding &Request across await)
let token = extract_bearer_token(&request);
<<<<<<< HEAD
// Resolve client_id and populate AuthInfo: DB token lookup, then prefix fallback
let auth_info = resolve_auth_info(token, &state).await;
let client_id = auth_info.client_id.clone();
=======
// Resolve token to client ID (with DB lookup if applicable)
let resolution = crate::auth::TokenResolution::resolve(token, &state).await;
>>>>>>> 76e5b9f (perf(auth): eliminate duplicate token resolution database queries)
// Store resolution in request extensions for downstream handlers
request.extensions_mut().insert(resolution.clone());
// Check rate limits using the rate-limit client ID
if !state.rate_limit_manager.check_client_request(&resolution.client_id_for_rate_limit).await? {
// Check rate limits
if !state.rate_limit_manager.check_client_request(&client_id).await? {
return Err(AppError::RateLimitError("Rate limit exceeded".to_string()));
}
@@ -346,7 +339,6 @@ pub mod middleware {
.map(|t| t.to_string())
}
<<<<<<< HEAD
/// Resolve auth info: try DB token first, then fall back to token-prefix derivation
async fn resolve_auth_info(token: Option<String>, state: &AppState) -> AuthInfo {
if let Some(token) = token {
@@ -382,8 +374,6 @@ pub mod middleware {
}
}
=======
>>>>>>> 76e5b9f (perf(auth): eliminate duplicate token resolution database queries)
/// Circuit breaker middleware for provider requests
pub async fn circuit_breaker_middleware(provider_name: &str, state: &AppState) -> Result<(), AppError> {
if !state.rate_limit_manager.check_provider_request(provider_name).await? {