commit 9a89284e4f37d77bc6408464d46a8d7a2a832aab
parent 32d2037c8eff5549485ece02769b9daf67f728ca
Author: Silas Brack <silasbrack@gmail.com>
Date: Sun, 7 Jun 2026 15:31:19 +0200
refactor: reuse shared reqwest client for registration
Store a single reqwest::Client in AppState instead of creating
a new one per registration request.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/handlers/auth.rs b/src/handlers/auth.rs
@@ -128,7 +128,7 @@ pub async fn register(
}
// Register the user
- match trailbase::register(&client, &form.email, &form.password).await {
+ match trailbase::register(&client, &state.http_client, &form.email, &form.password).await {
Ok(tokens) => {
// Create authenticated client and user profile
if let Ok(auth_client) = trailbase::client_with_tokens(&state.trailbase_url, &tokens) {
diff --git a/src/state.rs b/src/state.rs
@@ -3,12 +3,14 @@ use crate::config::Config;
#[derive(Clone)]
pub struct AppState {
pub trailbase_url: String,
+ pub http_client: reqwest::Client,
}
impl AppState {
pub fn new(config: &Config) -> Self {
Self {
trailbase_url: config.trailbase_url.clone(),
+ http_client: reqwest::Client::new(),
}
}
}
diff --git a/src/trailbase.rs b/src/trailbase.rs
@@ -645,7 +645,7 @@ pub async fn login(client: &Client, email: &str, password: &str) -> Result<Store
})
}
-pub async fn register(client: &Client, email: &str, password: &str) -> Result<StoredTokens, ClientError> {
+pub async fn register(client: &Client, http_client: &reqwest::Client, email: &str, password: &str) -> Result<StoredTokens, ClientError> {
#[derive(Serialize)]
struct RegisterRequest<'a> {
email: &'a str,
@@ -654,7 +654,6 @@ pub async fn register(client: &Client, email: &str, password: &str) -> Result<St
}
let url = format!("{}api/auth/v1/register", client.base_url());
- let http_client = reqwest::Client::new();
let response = http_client
.post(&url)
.json(&RegisterRequest {