feat: refacto auth#79
Open
Quentintnrl wants to merge 5 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the auth area by introducing first-login forced password change plus forgot/reset password flows, and adds SMTP email sending support (with local Mailpit integration) to support password reset delivery.
Changes:
- Add new auth endpoints:
forgot_password,reset_password, andforce_change_password, plus updated login flow to handle first-connection. - Add new DB queries/views to support user-id lookup, password changes, and first-connection state.
- Add SMTP email helper utilities (lettre) and local docker-compose Mailpit configuration.
Reviewed changes
Copilot reviewed 42 out of 43 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/auth/login.rs | Updates login query test to include first_connect in result view. |
| src/lib.rs | Adds lettre-based email builder/sender utilities and SMTP env configuration. |
| src/endpoints/v1/auth/reset_password/view.rs | Adds request/response DTOs for reset password. |
| src/endpoints/v1/auth/reset_password/mod.rs | Wires reset password module. |
| src/endpoints/v1/auth/reset_password/endpoint.rs | Implements reset password endpoint (token → email → password update → session). |
| src/endpoints/v1/auth/reset_password/doc.rs | Adds OpenAPI doc wrapper for reset password. |
| src/endpoints/v1/auth/mod.rs | Registers new auth services into /auth scope. |
| src/endpoints/v1/auth/login/view.rs | Consolidates login request/response DTOs and adds first-connection response DTO. |
| src/endpoints/v1/auth/login/mod.rs | Switches login module exports to consolidated view. |
| src/endpoints/v1/auth/login/login_view.rs | Removes old login request DTO file (moved). |
| src/endpoints/v1/auth/login/login_response_view.rs | Removes old login response DTO file (moved). |
| src/endpoints/v1/auth/login/endpoint.rs | Updates login flow: first-connect token + reusable session generation helper. |
| src/endpoints/v1/auth/login/doc.rs | Updates OpenAPI schemas for login. |
| src/endpoints/v1/auth/forgot_password/view.rs | Adds forgot password request DTO. |
| src/endpoints/v1/auth/forgot_password/mod.rs | Wires forgot password module. |
| src/endpoints/v1/auth/forgot_password/endpoint.rs | Implements forgot password: create token, store in Redis, send email. |
| src/endpoints/v1/auth/forgot_password/doc.rs | Adds OpenAPI doc wrapper for forgot password. |
| src/endpoints/v1/auth/force_change_password/view.rs | Adds force-change-password request DTO. |
| src/endpoints/v1/auth/force_change_password/mod.rs | Wires force change password module. |
| src/endpoints/v1/auth/force_change_password/endpoint.rs | Implements forced password change using first-connection token. |
| src/endpoints/v1/auth/force_change_password/doc.rs | Adds OpenAPI doc wrapper for force change password. |
| src/endpoints/v1/auth/doc.rs | Adds nested OpenAPI docs for new auth endpoints. |
| src/database/mod.rs | Exposes new get_user_id module. |
| src/database/get_user_id/view.rs | Adds query view to fetch user id by email. |
| src/database/get_user_id/query.rs | Adds SQL query to fetch user id by email. |
| src/database/get_user_id/mod.rs | Exports get_user_id query/view. |
| src/database/auth/unset_first_connection/view.rs | Adds query view for updating first_connect and password. |
| src/database/auth/unset_first_connection/query.rs | Adds query executor for first-connection unsetting. |
| src/database/auth/unset_first_connection/mod.rs | Exports unset-first-connection query/view. |
| src/database/auth/mod.rs | Exposes new auth DB modules (change_password, is_first_time, unset_first_connection). |
| src/database/auth/login/view.rs | Extends login query to return first_connect and moves result view inline. |
| src/database/auth/login/result_view.rs | Removes old result view file (moved). |
| src/database/auth/login/mod.rs | Re-exports login query view + result view from single module. |
| src/database/auth/is_first_time/view.rs | Adds query view intended to check “first time”. |
| src/database/auth/is_first_time/query.rs | Adds query executor for first-time check. |
| src/database/auth/is_first_time/mod.rs | Exports is-first-time query/view. |
| src/database/auth/change_password/view.rs | Adds query view for changing password. |
| src/database/auth/change_password/query.rs | Adds query executor for changing password. |
| src/database/auth/change_password/mod.rs | Exports change-password query/view. |
| entrypoint.sh | Uses cargo watch --poll for dev container. |
| docker-compose.yml | Updates images, adds Mailpit service + SMTP env vars, adjusts dependencies. |
| Cargo.toml | Adds lettre dependency for SMTP email sending. |
| Cargo.lock | Locks new dependency tree (lettre + transitive updates). |
Comments suppressed due to low confidence (2)
src/endpoints/v1/auth/forgot_password/endpoint.rs:149
- Multiple Redis calls use
state.get_redis_conn().await.unwrap(), which can panic and crash the service if Redis is unavailable. Since you already have aResetPasswordError::RedisError, return that on connection failures instead of unwrapping.
async fn trigger(state: web::Data<AppState>, email: &str) -> Result<(), ResetPasswordError> {
let token = Uuid::new_v4().to_string();
handle_secure_post(
state.get_redis_conn().await.unwrap(),
&format!("{}/forgot_password_token", email),
&token,
)
.await
.map_err(|e| {
eprintln!("Redis Error: {}", e);
ResetPasswordError::RedisError
})?;
handle_secure_post(
state.get_redis_conn().await.unwrap(),
&format!("{}/forgot_password_email", token),
&format!("{}", email),
)
.await
src/endpoints/v1/auth/reset_password/endpoint.rs:118
- Redis deletions also use
state.get_redis_conn().await.unwrap(). If Redis is down, this will panic before you can returnResetPasswordError::RedisError. Handle connection acquisition failures and map them toRedisErrorinstead.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CarolinHugo
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.