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
  • !8

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

feat(auth): support avatar file upload and enforce gmail registration

Overview

This PR enhances the authentication module with two key requirements:

  1. Gmail Registration Restriction: Enforces that all newly registered accounts must use a @gmail.com email address.
  2. Avatar File Upload Pipeline: Transitions avatar updates from manual URL inputs to direct image file uploads (multipart/form-data), backed by the abstract storage layer (IStorageService).

Key Changes

1. Gmail Domain Enforcement

  • Updated registerSchema with validation ensuring email addresses end with @gmail.com (case-insensitive).
  • Added unit tests covering standard Gmail addresses, sub-addressing (+tag), and rejection of non-Gmail domains.

2. Avatar Upload Middleware

  • Integrated multer with memory storage.
  • Added uploadAvatarMiddleware enforcing a 5MB maximum file size and strict image MIME type validation (image/jpeg, image/png, image/webp, image/gif), throwing standardized AppError (422 VALIDATION_ERROR).

3. Service & Storage Integration

  • AuthService.uploadAvatar:
    • Streams image buffers directly to IStorageService under avatars/<userId>-<timestamp>.<ext>.
    • Automatically cleans up obsolete avatar files from storage when a new avatar is uploaded.
    • Updates the user record in PostgreSQL and returns the updated user profile.
  • AuthService.getAvatarStream:
    • Validates and securely reads stored avatar files with MIME detection for HTTP streaming.
  • Profile Update Decoupling:
    • Removed avatarUrl from UpdateMeDto and updateMeSchema. The PATCH /api/v1/auth/me endpoint now strictly handles profile fields (fullName).

4. Endpoints & Audit Logging

  • POST /api/v1/auth/avatar: Authenticated multipart upload endpoint.
  • GET /api/v1/auth/avatar/:fileName: Public endpoint serving uploaded avatars.
  • Added UPDATE_AVATAR action to AUDIT_ACTIONS.

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/auth-avatar-upload-and-gmail-validation origin/feat/auth-avatar-upload-and-gmail-validation

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/auth-avatar-upload-and-gmail-validation

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 14
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!8

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.