User Management API

Complete reference for user profile management, settings, usage statistics, and account operations.

User Management Overview

The User Management API provides functionality for managing user profiles, settings, storage usage, and account operations in MegaVault.

Profile Management

User information

  • ✅ Profile information
  • ✅ Avatar management
  • ✅ Contact details
  • ✅ Account preferences

Usage Analytics

Storage and activity

  • ✅ Storage usage tracking
  • ✅ File upload statistics
  • ✅ Activity logs
  • ✅ Quota management

Account Security

Security settings

  • ✅ Password management
  • ✅ Session management
  • ✅ Privacy settings
  • ✅ Account deletion
💡

Authentication Required

All user management endpoints require authentication. Users can only access and modify their own data.

Get User Profile

Retrieve the current user's profile information and account details.

Request
GET /api/users/profile
Authorization: Bearer YOUR_JWT_TOKEN

Response

Success Response (200)
{
  "success": true,
  "data": {
    "id": "user_123456789",
    "email": "user@example.com",
    "name": "John Doe",
    "avatar": "https://storage.example.com/avatars/user_123456789.jpg",
    "bio": "Cloud storage enthusiast and developer",
    "location": "San Francisco, CA",
    "website": "https://johndoe.dev",
    "plan": {
      "type": "pro",
      "name": "Pro Plan",
      "storageLimit": 107374182400,
      "features": ["unlimited_uploads", "advanced_sharing", "priority_support"]
    },
    "preferences": {
      "theme": "dark",
      "language": "en",
      "timezone": "America/Los_Angeles",
      "notifications": {
        "email": true,
        "push": true,
        "uploads": true,
        "sharing": true
      }
    },
    "stats": {
      "filesCount": 1247,
      "foldersCount": 89,
      "storageUsed": 5368709120,
      "totalUploads": 2456,
      "lastLoginAt": "2024-01-20T14:30:00Z"
    },
    "createdAt": "2023-06-15T10:30:00Z",
    "emailVerified": true,
    "isActive": true
  }
}

Update Profile

Update user profile information including personal details and preferences.

Request
PUT /api/users/profile
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "name": "John Smith",
  "bio": "Full-stack developer and cloud enthusiast",
  "location": "New York, NY",
  "website": "https://johnsmith.dev",
  "preferences": {
    "theme": "light",
    "language": "en",
    "timezone": "America/New_York"
  }
}

Response

Success Response (200)
{
  "success": true,
  "data": {
    "id": "user_123456789",
    "name": "John Smith",
    "bio": "Full-stack developer and cloud enthusiast",
    "location": "New York, NY",
    "website": "https://johnsmith.dev",
    "preferences": {
      "theme": "light",
      "language": "en",
      "timezone": "America/New_York"
    },
    "updatedAt": "2024-01-20T15:45:00Z"
  },
  "message": "Profile updated successfully"
}

Updatable Fields

  • name: Display name (2-50 characters)
  • bio: Profile bio (max 200 characters)
  • location: Location information (optional)
  • website: Personal website URL (optional)
  • preferences: User preferences object

Upload Avatar

Avatar Upload Request
POST /api/users/avatar
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data

Form Data:
avatar: [IMAGE_FILE]
Avatar Upload Response
{
  "success": true,
  "data": {
    "avatarUrl": "https://storage.example.com/avatars/user_123456789.jpg",
    "updatedAt": "2024-01-20T16:00:00Z"
  },
  "message": "Avatar updated successfully"
}

Get Usage Statistics

Retrieve detailed storage usage and activity statistics for the current user.

Request
GET /api/users/usage?period=30d
Authorization: Bearer YOUR_JWT_TOKEN

Query Parameters

  • period: Time period for statistics (7d, 30d, 90d, 1y) - default: 30d
  • detailed: Include detailed breakdown (true/false) - default: false

Response

Success Response (200)
{
  "success": true,
  "data": {
    "period": "30d",
    "storage": {
      "used": 5368709120,
      "limit": 107374182400,
      "usagePercentage": 5.0,
      "breakdown": {
        "documents": 2147483648,
        "images": 1610612736,
        "videos": 1073741824,
        "audio": 268435456,
        "other": 268435456
      }
    },
    "activity": {
      "uploads": {
        "count": 45,
        "totalSize": 536870912,
        "avgSize": 11930464
      },
      "downloads": {
        "count": 123,
        "totalSize": 2147483648
      },
      "shares": {
        "created": 8,
        "accessed": 156
      },
      "deletions": {
        "count": 12,
        "reclaimedSpace": 134217728
      }
    },
    "trends": {
      "dailyUploads": [
        {"date": "2024-01-01", "count": 2, "size": 10485760},
        {"date": "2024-01-02", "count": 5, "size": 52428800}
      ],
      "storageGrowth": [
        {"date": "2024-01-01", "size": 5100000000},
        {"date": "2024-01-20", "size": 5368709120}
      ]
    },
    "generatedAt": "2024-01-20T16:30:00Z"
  }
}

Update Settings

Update user account settings including notifications, privacy, and app preferences.

Request
PUT /api/users/settings
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "notifications": {
    "email": true,
    "push": false,
    "uploads": true,
    "sharing": true,
    "storage": true,
    "security": true
  },
  "privacy": {
    "publicProfile": false,
    "showActivity": false,
    "allowIndexing": false
  },
  "app": {
    "autoUpload": true,
    "compressionEnabled": true,
    "thumbnailGeneration": true,
    "defaultFolder": "/uploads"
  }
}

Response

Success Response (200)
{
  "success": true,
  "data": {
    "notifications": {
      "email": true,
      "push": false,
      "uploads": true,
      "sharing": true,
      "storage": true,
      "security": true
    },
    "privacy": {
      "publicProfile": false,
      "showActivity": false,
      "allowIndexing": false
    },
    "app": {
      "autoUpload": true,
      "compressionEnabled": true,
      "thumbnailGeneration": true,
      "defaultFolder": "/uploads"
    },
    "updatedAt": "2024-01-20T17:00:00Z"
  },
  "message": "Settings updated successfully"
}

Settings Categories

  • notifications: Email and push notification preferences
  • privacy: Profile visibility and data sharing settings
  • app: Application behavior and feature settings

Change Password

Update the user's account password with proper verification.

Request
PUT /api/users/password
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "currentPassword": "currentSecurePassword123",
  "newPassword": "newSecurePassword456",
  "confirmPassword": "newSecurePassword456"
}

Response

Success Response (200)
{
  "success": true,
  "message": "Password updated successfully",
  "data": {
    "passwordChangedAt": "2024-01-20T17:15:00Z",
    "sessionInvalidated": true
  }
}

Password Requirements

  • Length: Minimum 8 characters
  • Complexity: Must include uppercase, lowercase, and numbers
  • Verification: Current password must be provided
  • Confirmation: New password must be confirmed
⚠️

Session Invalidation

Changing password will invalidate all existing sessions except the current one. Users will need to log in again on other devices.

Delete Account

Permanently delete the user account and all associated data.

Request
DELETE /api/users/account
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "password": "userPassword123",
  "confirmation": "DELETE_MY_ACCOUNT",
  "reason": "No longer needed"
}

Response

Success Response (200)
{
  "success": true,
  "message": "Account scheduled for deletion",
  "data": {
    "scheduledDeletionAt": "2024-01-27T17:30:00Z",
    "gracePeriodEnds": "2024-01-27T17:30:00Z",
    "recoveryCode": "recovery_abc123def456"
  }
}

Account Deletion Process

  1. Verification: Password and confirmation text required
  2. Grace Period: 7-day grace period before permanent deletion
  3. Data Removal: All files, folders, and user data will be deleted
  4. Recovery: Account can be recovered during grace period

Recover Deleted Account

Recovery Request
POST /api/users/recover
Content-Type: application/json

{
  "email": "user@example.com",
  "recoveryCode": "recovery_abc123def456"
}

Permanent Deletion Warning

Account deletion is irreversible after the grace period. All files, settings, and user data will be permanently removed and cannot be recovered.