commit 32d2037c8eff5549485ece02769b9daf67f728ca
parent 6d1aea792c05fb48819dcadf3a912748819aab93
Author: Silas Brack <silasbrack@gmail.com>
Date: Sun, 7 Jun 2026 14:32:05 +0200
fix: show success page instead of error for email verification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/src/handlers/auth.rs b/src/handlers/auth.rs
@@ -128,29 +128,28 @@ pub async fn register(
}
// Register the user
- let tokens = match trailbase::register(&client, &form.email, &form.password).await {
- Ok(t) => t,
+ match trailbase::register(&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) {
+ if let Err(e) = trailbase::create_user_profile(&auth_client, &form.username).await {
+ tracing::warn!("Failed to create user profile: {}", e);
+ }
+ }
+
+ let jar = set_auth_cookie(jar, &tokens);
+ Ok((jar, Redirect::to("/")))
+ }
+ Err(trailbase::ClientError::EmailVerificationRequired) => {
+ Err(render_register_success("Registration successful! Please check your email to verify your account."))
+ }
Err(e) => {
- return Err(render_register_error(
+ Err(render_register_error(
&form,
&format!("Registration failed: {}", e),
- ));
+ ))
}
- };
-
- // Create authenticated client
- let auth_client = trailbase::client_with_tokens(&state.trailbase_url, &tokens).map_err(|e| {
- render_register_error(&form, &format!("Client error: {}", e))
- })?;
-
- // Create user profile
- if let Err(e) = trailbase::create_user_profile(&auth_client, &form.username).await {
- // Log the error but don't fail registration
- tracing::warn!("Failed to create user profile: {}", e);
}
-
- let jar = set_auth_cookie(jar, &tokens);
- Ok((jar, Redirect::to("/")))
}
pub async fn logout(jar: CookieJar) -> (CookieJar, Redirect) {
@@ -168,6 +167,12 @@ fn render_login_error(error: &str) -> Html<String> {
Html(app.render().unwrap_or_default())
}
+fn render_register_success(message: &str) -> Html<String> {
+ let content = format!("<div class=\"auth-page\"><h2>Check Your Email</h2><p>{}</p><p class=\"auth-link\"><a href=\"/login\">Go to Login</a></p></div>", message);
+ let app = ApplicationTemplate { content };
+ Html(app.render().unwrap_or_default())
+}
+
fn render_register_error(form: &RegisterForm, error: &str) -> Html<String> {
let register = RegisterTemplate {
error: Some(error.to_string()),
diff --git a/src/trailbase.rs b/src/trailbase.rs
@@ -13,6 +13,8 @@ pub enum ClientError {
TrailBase(#[from] trailbase_client::Error),
#[error("Auth error: {0}")]
Auth(String),
+ #[error("Email verification required")]
+ EmailVerificationRequired,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -673,9 +675,7 @@ pub async fn register(client: &Client, email: &str, password: &str) -> Result<St
// If redirected (303), registration succeeded but email verification may be required.
// Try to log in — if email verification is enabled, this may fail.
if let Err(_) = client.login(email, password).await {
- return Err(ClientError::Auth(
- "Registration successful! Please check your email to verify your account.".into(),
- ));
+ return Err(ClientError::EmailVerificationRequired);
}
let tokens = client.tokens().ok_or_else(|| {