Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in
U
upgrade-data-crawler-be
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • ThinhNC
  • upgrade-data-crawler-be
  • Merge Requests
  • !6

Merged
Opened Sep 03, 2026 by ThinhNC@ThinhNC
  • Report abuse
Report abuse

feat(auth): implement user self-deactivation with email verification

Summary of Changes

Implemented a secure, two-step User Account Self-Deactivation flow with email verification in compliance with the strict 5-layer architecture and audit safety standards.

Business & Security Invariants

  1. Two-Step Verification Flow:
    • POST /api/v1/auth/deactivate/request: Requires authenticated user session, validates current password via bcrypt, derives a time-limited (15-minute) signed JWT token bound to passwordHash (purpose: "deactivate-account"), and dispatches a verification email.
    • POST /api/v1/auth/deactivate/confirm: Cryptographically verifies the token, marks user as inactive (isActive = false, deletedAt = NOW(), deletedBy = userId), revokes sessions, and clears client authentication cookies.
  2. Zero Token Leakage:
    • The deactivation token is handled strictly inside the service layer and sent via the email service. It is never returned in API responses or leaked across architectural layers.
  3. Sole Admin Lockout Protection:
    • Deactivation requests and confirmations are rejected with a validation error if the requesting user is the last remaining active Admin in the system, preventing accidental orphan administrative lockout.
  4. Comprehensive Revocation via Atomic Transaction:
    • Executes inside a database transaction:
      • Soft-deletes user record (isActive = false, deletedAt = NOW(), deletedBy = userId).
      • Deletes all active refresh tokens for the user.
      • Deactivates all associated API keys (isActive = false).
      • Deactivates all associated crawl schedules (isActive = false).
  5. Strict Layering & Zero Hardcode Compliance:
    • Only repository interacts with the database.
    • Utilizes shared domain constants for roles and audit actions without hardcoded string literals.

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b feat/user-account-self-deactivation origin/feat/user-account-self-deactivation

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/develop
git merge --no-ff feat/user-account-self-deactivation

Step 4. Push the result of the merge to GitLab

git push origin develop

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 0
  • Commits 1
  • Changes 12
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: ThinhNC/upgrade-data-crawler-be!6

Revert this merge request

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.