Profile Management Service

⚠️ CRITICAL REQUIREMENTS

🔐 Authentication Required

ALL endpoints in this service require Bearer token authentication. No exceptions. Requests without valid authentication will receive a 401 Unauthorized response.

🚨 Username Change Token Invalidation

CRITICAL: When updating a username via /update-basic-info, the user's current access token becomes invalid immediately after the change. The frontend MUST:

  1. Redirect to login page after successful username change

  2. Clear all stored tokens (access token, refresh token)

  3. Force re-authentication with the new username

  4. Display appropriate message informing user of required re-login

🖼️ Profile Picture URL Restriction

IMPORTANT: The profilePictureUrls field ONLY accepts URLs generated from our File Upload Service endpoint (/api/v1/files/upload). External URLs or direct links are NOT permitted for security reasons.

Valid URL Format: http://localhost:9005/{bucket-name}/{object-key} Source: Must be uploaded through /api/v1/files/upload with directory=PROFILE


Service Overview

The Profile Management Service provides comprehensive user profile management capabilities including profile updates, security settings, verification, and account management.

Base URL

Endpoints Overview

Method
Endpoint
Description

GET

/me

Get current user profile

PUT

/update-basic-info

Update basic profile information

PUT

/change-password

Change user password

GET

/validate-username/{username}

Validate username availability

POST

/request-email-verification

Request email verification

POST

/verify-email

Verify email with OTP

GET

/security-info

Get security information

POST

/enable-2fa

Enable two-factor authentication

POST

/disable-2fa

Disable two-factor authentication

DELETE

/deactivate

Deactivate user account


Get Current User Profile

Retrieves the complete profile information for the authenticated user.

Request

Response

Error Responses


Update Basic Profile Information

Updates basic user profile information including name, email, username, and profile pictures.

Request

Request Body

Field Validation

  • userName: 3-30 characters, must start with letter, alphanumeric + underscore/hyphen only

  • firstName: 1-30 characters, required

  • lastName: 1-30 characters, required

  • middleName: Max 30 characters, optional

  • email: Valid email format

  • phoneNumber: International format (+1234567890)

  • profilePictureUrls:

    • Max 5 URLs

    • Each URL max 500 characters

    • MUST be URLs from File Upload Service only (/api/v1/files/upload-single with directory=PROFILE)

    • External URLs are rejected for security reasons

Response (Normal Update)

⚠️ CRITICAL: Username Change Response

When the username is updated, the response includes a special message and the frontend MUST handle token invalidation:

IMMEDIATE ACTION REQUIRED:

  1. Clear all stored tokens (access token, refresh token)

  2. Redirect user to login page

  3. Display the message to inform user of required re-authentication

  4. User must login again with their NEW username

Error Responses


Change Password

Changes the user's password with current password verification.

Request

Request Body

Password Requirements

  • Minimum 8 characters

  • At least one uppercase letter

  • At least one lowercase letter

  • At least one digit

  • At least one special character (@$!%*?&#)

  • Must be different from current password

Response

Error Responses


Validate Username

Checks username availability and format validity with suggestions.

Request

Response (Available)

Response (Not Available)


Request Email Verification

Sends an OTP to the user's email for verification.

Request

Response

Error Responses


Verify Email

Verifies email address using the OTP code sent via email.

Request

Request Body

Response

Error Responses


Get Security Information

Retrieves comprehensive security information and account strength analysis.

Request

Response

Security Strength Scoring

  • Email Verification: 25 points

  • Phone Verification: 25 points

  • Two-Factor Authentication: 35 points

  • Recent Password Change (last 6 months): 15 points

Security Levels

  • 80-100: STRONG - "Your account security is excellent"

  • 60-79: MEDIUM - "Your account security is good but can be improved"

  • 40-59: WEAK - "Your account security needs improvement"

  • 0-39: VERY_WEAK - "Your account security is poor and needs immediate attention"


Enable Two-Factor Authentication

Enables two-factor authentication for the user account.

Request

Request Body

Response

Error Responses


Disable Two-Factor Authentication

Disables two-factor authentication for the user account.

Request

Request Body

Response

Error Responses


Deactivate Account

Deactivates (soft deletes) the user account by locking it.

Request

Request Body

Response

Error Responses


Common Error Responses

Authentication Errors

ALL endpoints require valid Bearer token authentication:

Validation Errors

Rate Limiting Errors


Security Features

Password Strength Analysis

The system analyzes password strength based on:

  • Length (minimum 8 characters)

  • Character diversity (uppercase, lowercase, numbers, special characters)

  • Common password patterns

Rate Limiting

  • OTP requests: Limited to prevent abuse

  • Failed attempts: Tracked and limited

  • Cooldown periods: Applied between requests

Email Notifications

  • Password changes trigger security notifications

  • Account deactivation confirmations

  • Verification code deliveries

Data Validation

  • Input sanitization for XSS prevention

  • URL validation for profile pictures

  • Phone number format validation

  • Email format validation

Profile Picture Security

  • Maximum 5 URLs per user

  • URL length limits (500 characters)

  • ONLY accepts URLs from File Upload Service (/api/v1/files/upload-single)

  • Format validation (image extensions only)

  • External URL blocking for security (SSRF protection)

  • Valid URL pattern: http://localhost:9005/{bucket-name}/{object-key}


Best Practices for Frontend Integration

⚠️ Critical Authentication Handling

  1. Token Validation: Always check token validity before making requests

  2. Token Storage: Store access tokens securely

  3. Username Change Flow:

    • Detect username change response message

    • Immediately clear all stored authentication data

    • Redirect to login page with appropriate message

    • Force user to re-authenticate with new username

  4. Token Refresh: Implement proper token refresh mechanisms

  5. Error Handling: Handle 401 errors by redirecting to login

Security Considerations

  1. Password Handling: Never log or persist passwords

  2. Form Validation: Implement client-side validation matching server rules

  3. Error Messages: Display user-friendly error messages without exposing sensitive information

  4. Loading States: Show appropriate loading indicators for async operations

  5. Session Management: Clear all user data on authentication failures

Username Change Implementation Requirements

When handling username update responses, the frontend must:

  1. Check Response Message: Look for the specific message "Username changed successfully! You will be logged out automatically..."

  2. Clear Authentication Data: Remove all stored tokens and user session data

  3. User Notification: Display the response message to inform user of required re-authentication

  4. Force Re-login: Redirect user to login page immediately

  5. Block Further API Calls: Prevent any additional authenticated requests until re-login

User Experience

  1. Progressive Disclosure: Show security strength indicators

  2. Real-time Validation: Validate usernames and emails as user types

  3. Clear Feedback: Provide immediate feedback for actions

  4. Confirmation Dialogs: Confirm destructive actions like account deactivation

  5. Auto-logout: Handle username changes by logging user out

Performance

  1. Debounced Validation: Debounce username validation requests

  2. Caching: Cache profile data appropriately

  3. Optimistic Updates: Update UI optimistically where safe

  4. Error Recovery: Implement retry mechanisms for failed requests

Profile Picture Handling

  1. File Upload First: Always upload images via File Upload Service before updating profile

  2. URL Validation: Only use URLs returned from /api/v1/files/upload-single

  3. Error Handling: Handle profile picture URL validation errors appropriately

  4. Preview: Show image previews before updating profile

Last updated