Skip to content

feat: refacto auth#79

Open
Quentintnrl wants to merge 5 commits into
mainfrom
mair-69-refacto-auth
Open

feat: refacto auth#79
Quentintnrl wants to merge 5 commits into
mainfrom
mair-69-refacto-auth

Conversation

@Quentintnrl
Copy link
Copy Markdown
Contributor

No description provided.

@Quentintnrl Quentintnrl self-assigned this May 19, 2026
Copilot AI review requested due to automatic review settings May 19, 2026 10:19
@Quentintnrl Quentintnrl linked an issue May 19, 2026 that may be closed by this pull request
@Quentintnrl Quentintnrl enabled auto-merge (squash) May 19, 2026 10:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and force_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 a ResetPasswordError::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 return ResetPasswordError::RedisError. Handle connection acquisition failures and map them to RedisError instead.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database/auth/unset_first_connection/view.rs
Comment thread src/database/auth/is_first_time/view.rs
Comment thread src/database/auth/change_password/view.rs
Comment thread src/endpoints/v1/auth/login/view.rs
Comment thread src/endpoints/v1/auth/login/endpoint.rs
Comment thread src/endpoints/v1/auth/reset_password/doc.rs
Comment thread src/endpoints/v1/auth/doc.rs
Comment thread docker-compose.yml
Comment thread src/database/get_user_id/query.rs
Comment thread src/database/auth/unset_first_connection/query.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAIR-69 refacto auth

3 participants