diff --git a/backend/src/services/auth.rs b/backend/src/services/auth.rs index 4c13be4..7c8f541 100644 --- a/backend/src/services/auth.rs +++ b/backend/src/services/auth.rs @@ -64,13 +64,17 @@ pub async fn create_and_send_magic_link( app_url: &str, to_email: &str, ) -> Result<(), AppError> { + tracing::info!(email = to_email, "Sending magic link email"); + let Some(raw_token) = create_magic_link(pool, to_email).await? else { + tracing::warn!(email = to_email, "Magic link not sent: rate limit reached"); return Ok(()); }; if let Err(e) = email::send_magic_link(http_client, resend_api_key, email_from, to_email, app_url, &raw_token).await { + tracing::error!(email = to_email, error = %e, "Magic link email failed, rolling back token"); let token_hash = token::hash_token(&raw_token); db::magic_links::delete_by_hash(pool, &token_hash).await.ok(); return Err(e);