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

# Authentication Endpoints

> User authentication and account management endpoints

# Authentication API

## Login User

<Card title="POST /auth/login" icon="sign-in">
  Authenticate a user with email and password
</Card>

**Base URL**: `https://rzqklwfhwqmviintncqh.supabase.co/functions/v1`

### Request

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

<ParamField header="apikey" type="string" required>
  Your Supabase anon key
</ParamField>

<ParamField body="email" type="string" required>
  User's email address
</ParamField>

<ParamField body="password" type="string" required>
  User's password
</ParamField>

### Response

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

<ResponseField name="statusCode" type="number">
  HTTP status code
</ResponseField>

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

<ResponseField name="data" type="object">
  <Expandable title="data">
    <ResponseField name="payload" type="object">
      <Expandable title="payload">
        <ResponseField name="id" type="string">User's unique identifier</ResponseField>
        <ResponseField name="name" type="string">User's full name</ResponseField>
        <ResponseField name="email" type="string">User's email address</ResponseField>
        <ResponseField name="role" type="string">User's role (STANDARD\_USER, ADMIN)</ResponseField>
        <ResponseField name="status" type="string">Account status (ACTIVE, SUSPENDED)</ResponseField>
        <ResponseField name="isVerified" type="boolean">Email verification status</ResponseField>
        <ResponseField name="createdAt" type="string">Account creation timestamp</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="accessToken" type="string">JWT token for API authentication</ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/auth/login \
    -H "Content-Type: application/json" \
    -H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
    -d '{
      "email": "user@example.com",
      "password": "userpassword"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/auth/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
    },
    body: JSON.stringify({
      email: 'user@example.com',
      password: 'userpassword'
    })
  });

  const data = await response.json();
  ```

  ```dart Flutter theme={null}
  final response = await http.post(
    Uri.parse('https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/auth/login'),
    headers: {
      'Content-Type': 'application/json',
      'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
    },
    body: jsonEncode({
      'email': 'user@example.com',
      'password': 'userpassword',
    }),
  );
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "success": true,
    "statusCode": 200,
    "message": "Welcome back",
    "data": {
      "payload": {
        "id": "f9cc094c-ba9c-4a0a-82b9-e40d589e97db",
        "name": "John Doe",
        "phoneNumber": null,
        "email": "user@example.com",
        "role": "STANDARD_USER",
        "status": "ACTIVE",
        "isVerified": true,
        "createdAt": "2025-08-15T13:53:15.974Z",
        "updatedAt": "2025-08-15T13:53:15.974Z"
      },
      "accessToken": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImY5Y2MwOTRjLWJhOWMtNGEwYS04MmI5LWU0MGQ1ODllOTdkYiIsInJvbGUiOiJTVEFOREFSRF9VU0VSIiwiaWF0IjoxNzYwNDI2MzI4LCJleHAiOjE3NjA0MzM1Mjh9.6iIAZ8awuIAvEGBRDGfAfN31DI8vB2MjcXpVRLbbH0I"
    }
  }
  ```

  ```json Error Response theme={null}
  {
    "statusCode": 400,
    "message": "Invalid credentials"
  }
  ```
</ResponseExample>

***

## Register User

<Card title="POST /auth/register" icon="user-plus">
  Create a new user account
</Card>

### Request

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

<ParamField header="apikey" type="string" required>
  Your Supabase anon key
</ParamField>

<ParamField body="name" type="string" required>
  User's full name
</ParamField>

<ParamField body="email" type="string" required>
  User's email address
</ParamField>

<ParamField body="password" type="string" required>
  User's password (minimum 8 characters)
</ParamField>

### Response

Similar to login response with newly created user data.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/auth/register \
    -H "Content-Type: application/json" \
    -H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
    -d '{
      "name": "John Doe",
      "email": "john@example.com",
      "password": "securepassword123"
    }'
  ```
</RequestExample>

***

## Create Password

<Card title="POST /auth/create-password" icon="key">
  Set or update user password
</Card>

### Request

<ParamField body="email" type="string" required>
  User's email address
</ParamField>

<ParamField body="password" type="string" required>
  New password to set
</ParamField>

<ParamField body="code" type="string" required>
  Verification code issued by the password reset flow
</ParamField>

### Response

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

<ResponseField name="data" type="object">
  User data and new access token
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/auth/create-password \
    -H "Content-Type: application/json" \
    -H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
    -d '{
      "email": "user@example.com",
      "password": "newpassword123",
      "code": "123456"
    }'
  ```
</RequestExample>

## Error Codes

| Status Code | Error                 | Description                                     |
| ----------- | --------------------- | ----------------------------------------------- |
| 400         | Bad Request           | Invalid request body or missing required fields |
| 401         | Unauthorized          | Invalid credentials                             |
| 404         | Not Found             | User not found                                  |
| 500         | Internal Server Error | Server error occurred                           |

<Note>
  All authentication endpoints return JWT tokens that expire after 2 hours. Store tokens securely and handle expiration gracefully in your application.
</Note>
