commit cfcd136f9f62f5e20df384f95af056ed25f7e8c4
parent ac265c3704e81bc53637c26003f253252535a01a
Author: Silas Brack <silasbrack@gmail.com>
Date: Sun, 7 Jun 2026 18:17:34 +0200
fix: add URL validation error message and log profile creation failures
- Show clear error when URL is invalid instead of silent failure
- Log errors from profile creation on login instead of ignoring them
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/handlers/auth.rs b/src/handlers/auth.rs
@@ -73,9 +73,17 @@ pub async fn login(
// Ensure user has a profile, create one if missing
if let Ok(auth_client) = trailbase::client_with_tokens(&state.trailbase_url, &tokens) {
if let Some(user_id) = trailbase::extract_user_id_from_token(&tokens.auth_token) {
- if trailbase::get_user_profile_by_id(&auth_client, &user_id).await.ok().flatten().is_none() {
- let username = form.email.split('@').next().unwrap_or("user");
- let _ = trailbase::create_user_profile(&auth_client, username).await;
+ match trailbase::get_user_profile_by_id(&auth_client, &user_id).await {
+ Ok(Some(_)) => {},
+ Ok(None) => {
+ let username = form.email.split('@').next().unwrap_or("user");
+ if let Err(e) = trailbase::create_user_profile(&auth_client, username).await {
+ tracing::error!("Failed to create user profile for {}: {}", user_id, e);
+ }
+ }
+ Err(e) => {
+ tracing::error!("Failed to check user profile for {}: {}", user_id, e);
+ }
}
}
}
diff --git a/src/handlers/story.rs b/src/handlers/story.rs
@@ -176,6 +176,13 @@ pub async fn submit_story(
return Err(render_submit_error(&form, &all_tags, "Title is required"));
}
+ // Validate URL if provided
+ if let Some(u) = url {
+ if url::Url::parse(u).is_err() {
+ return Err(render_submit_error(&form, &all_tags, "Invalid URL. Must start with http:// or https://"));
+ }
+ }
+
// Extract domain from URL
let domain = url.and_then(|u| trailbase::extract_domain(u));