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

@@ -121,7 +121,6 @@ async fn chat_completions(
auth: AuthenticatedClient,
Json(mut request): Json<ChatCompletionRequest>,
) -> Result<axum::response::Response, AppError> {
<<<<<<< HEAD
let client_id = auth.client_id.clone();
let token = auth.token.clone();
@@ -132,28 +131,6 @@ async fn chat_completions(
return Err(AppError::AuthError("Invalid authentication token".to_string()));
}
}
=======
// Use the db_client_id from the AuthenticatedClient (already resolved by middleware)
let db_client_id = auth.db_client_id.clone();
let client_id = if let Some(cid) = db_client_id {
// Update last_used_at in background (fire-and-forget) for DB tokens
let pool = state.db_pool.clone();
let token = auth.token.clone();
tokio::spawn(async move {
let _ = sqlx::query("UPDATE client_tokens SET last_used_at = CURRENT_TIMESTAMP WHERE token = ?")
.bind(&token)
.execute(&pool)
.await;
});
cid
} else if state.auth_tokens.is_empty() || state.auth_tokens.contains(&auth.token) {
// Env token match or permissive mode (no env tokens configured)
auth.client_id.clone()
} else {
return Err(AppError::AuthError("Invalid authentication token".to_string()));
};
>>>>>>> 76e5b9f (perf(auth): eliminate duplicate token resolution database queries)
let start_time = std::time::Instant::now();
let model = request.model.clone();