> ## Documentation Index
> Fetch the complete documentation index at: https://docs.deployhub.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Profile Management

> Manage user profile information and profile picture

## Get User Profile

<RequestExample>
  ```bash theme={null}
  GET /api/me
  ```
</RequestExample>

Retrieves the authenticated user's profile information.

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

### Response

<ResponseField name="success" type="string">
  Indicates if the request was successful
</ResponseField>

<ResponseField name="data" type="object">
  User profile information

  <Expandable title="data properties">
    <ResponseField name="_id" type="string">
      User's unique identifier
    </ResponseField>

    <ResponseField name="fullname" type="string">
      User's full name
    </ResponseField>

    <ResponseField name="email" type="string">
      User's email address
    </ResponseField>

    <ResponseField name="provider" type="string">
      Authentication provider (`local` or `github`)
    </ResponseField>

    <ResponseField name="profilePic" type="string">
      URL to user's profile picture
    </ResponseField>

    <ResponseField name="verified" type="boolean">
      Whether the user's email is verified
    </ResponseField>

    <ResponseField name="updatedAt" type="string">
      Last update timestamp
    </ResponseField>

    <ResponseField name="createdAt" type="string">
      Account creation timestamp
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "data": {
      "_id": "507f1f77bcf86cd799439011",
      "fullname": "John Doe",
      "email": "john@example.com",
      "provider": "local",
      "profilePic": "https://cdn.deployhub.online/profile-123.jpg",
      "verified": true,
      "updatedAt": "2024-03-15T10:30:00.000Z",
      "createdAt": "2024-01-10T08:15:00.000Z"
    },
    "success": "true"
  }
  ```
</ResponseExample>

***

## Update Profile Picture

<RequestExample>
  ```bash theme={null}
  POST /api/user/profile-pic
  ```
</RequestExample>

Uploads and updates the user's profile picture. Uses multipart/form-data with multer middleware.

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

<ParamField header="Content-Type" type="string" required>
  Must be `multipart/form-data`
</ParamField>

### Body Parameters

<ParamField body="profilePic" type="file" required>
  Image file for the profile picture. Uploaded using multer with diskStorage configuration. Files are temporarily stored in the `uploads/` directory with a unique filename format: `profilePic-{timestamp}-{random}.{ext}`
</ParamField>

### Response

<ResponseField name="message" type="string">
  Success message
</ResponseField>

<ResponseField name="profilePic" type="string">
  Public URL of the uploaded profile picture
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "message": "Profile picture updated successfully",
    "profilePic": "https://cdn.deployhub.online/profile-1234567890.jpg"
  }
  ```
</ResponseExample>

### Implementation Details

* Multer storage configuration uses `diskStorage` with unique filename generation
* Old profile picture is deleted from Devload storage before uploading new one
* File is uploaded to Devload CDN and public URL is stored in database
* Local temporary file is automatically cleaned up after upload
* Updates both `profilePic` (URL) and `profilefileid` (storage reference) fields

### Error Responses

<ResponseExample>
  ```json theme={null}
  {
    "message": "File upload failed"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json theme={null}
  {
    "message": "File deletion failed"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json theme={null}
  {
    "message": "Internal server error"
  }
  ```
</ResponseExample>

***

## Update Full Name

<RequestExample>
  ```bash theme={null}
  PUT /api/user/fullname
  ```
</RequestExample>

Updates the user's full name.

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`
</ParamField>

### Body Parameters

<ParamField body="fullname" type="string" required>
  New full name for the user
</ParamField>

<RequestExample>
  ```json theme={null}
  {
    "fullname": "Jane Smith"
  }
  ```
</RequestExample>

### Response

<ResponseField name="success" type="boolean">
  Indicates if the update was successful
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "success": true
  }
  ```
</ResponseExample>

### Error Responses

<ResponseExample>
  ```json theme={null}
  {
    "message": "fullname is required"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json theme={null}
  {
    "error": "internal Server Error"
  }
  ```
</ResponseExample>

***

## Initialize Email Verification Payment

<RequestExample>
  ```bash theme={null}
  POST /api/me/init
  ```
</RequestExample>

Initiates a Razorpay payment order for email verification. Users must pay ₹99 to verify their email address.

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

### Response

<ResponseField name="id" type="string">
  Razorpay order ID
</ResponseField>

<ResponseField name="amount" type="number">
  Payment amount in paise (9900 = ₹99)
</ResponseField>

<ResponseField name="currency" type="string">
  Currency code (INR)
</ResponseField>

<ResponseField name="receipt" type="string">
  Order receipt ID
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "id": "order_NXHk3Mxl9rDEJZ",
    "amount": 9900,
    "currency": "INR",
    "receipt": "order_rcptid_0.123456789"
  }
  ```
</ResponseExample>

### Implementation Details

* Creates a Razorpay order with amount ₹99 (9900 paise)
* Customer details (email, name) are automatically included
* Creates a `VerifyuserPayment` record with status `pending`
* Order ID is stored for verification

### Error Responses

<ResponseExample>
  ```json theme={null}
  {
    "error": "Internal Server Error"
  }
  ```
</ResponseExample>

***

## Verify Email Verification Payment

<RequestExample>
  ```bash theme={null}
  POST /api/me/verify
  ```
</RequestExample>

Verifies the Razorpay payment signature and marks the user's email as verified.

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`
</ParamField>

### Body Parameters

<ParamField body="razorpay_payment_id" type="string" required>
  Payment ID from Razorpay checkout
</ParamField>

<ParamField body="razorpay_order_id" type="string" required>
  Order ID from the init endpoint
</ParamField>

<ParamField body="razorpay_signature" type="string" required>
  HMAC signature from Razorpay for verification
</ParamField>

<RequestExample>
  ```json theme={null}
  {
    "razorpay_payment_id": "pay_NXHk3Mxl9rDEJZ",
    "razorpay_order_id": "order_NXHk3Mxl9rDEJZ",
    "razorpay_signature": "9ef9e5c5c9c5e5c5c9c5e5c5c9c5e5c5"
  }
  ```
</RequestExample>

### Response

<ResponseField name="success" type="boolean">
  Indicates if verification was successful
</ResponseField>

<ResponseField name="verifed" type="boolean">
  Indicates if the user is now verified
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "success": true,
    "verifed": true
  }
  ```
</ResponseExample>

### Implementation Details

* Verifies payment signature using HMAC-SHA256
* Checks if order exists and matches user
* Prevents duplicate verification (checks if status is already `completed`)
* Updates user's `verified` field to `true`
* Sets `verifiedAt` timestamp
* Updates order status to `completed`

### Error Responses

<ResponseExample>
  ```json theme={null}
  {
    "message": "required details fro verify payment"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json theme={null}
  {
    "success": false,
    "message": "Payment verification failed!"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json theme={null}
  {
    "message": "User not found!"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json theme={null}
  {
    "message": "something went wrong! PLease Contact your team"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json theme={null}
  {
    "message": "Your Oder ALready PRocessed"
  }
  ```
</ResponseExample>

<Warning>
  The signature verification is critical for security. Never skip this step or accept unverified payments.
</Warning>
