# Authentication

## Login (email)

<mark style="color:green;">`POST`</mark> `https://multiply.arbre.in/api/login`

This endpoint allows you to authenticate a user using email

#### Headers

| Name   | Type   | Description      |
| ------ | ------ | ---------------- |
| Accept | string | application/json |

#### Request Body

| Name     | Type   | Description      |
| -------- | ------ | ---------------- |
| type     | string | email            |
| email    | string | email of user    |
| password | string | password of user |

{% tabs %}
{% tab title="200 " %}

```
{
    "status": true,
    "accessToken": "2|eiSgXjGLzJgWDWEpOrQP9Zz70cFvYRS5LGcVrAde"
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "status": false,
    "message": "Incorrect password"
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "status": false,
    "message": "User not found"
}
```

{% endtab %}

{% tab title="422 " %}

```
{
    "message": "The given data was invalid.",
    "errors": {
        "email": [
            "The email field is required."
        ],
        "password": [
            "The password field is required."
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## login (otp)

<mark style="color:green;">`POST`</mark> `https://multiply.arbre.in/api/login`

This endpoint allows you to authenticate a user using email

#### Headers

| Name   | Type   | Description      |
| ------ | ------ | ---------------- |
| Accept | string | application/json |

#### Request Body

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| type          | string | otp                  |
| phone\_number | string | phone number of user |

{% tabs %}
{% tab title="202 " %}

```
{
    "status": true,
    "token": "1101",
    "message": "OTP generated"
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "status": false,
    "message": "User not found"
}
```

{% endtab %}

{% tab title="422 " %}

```
{
    "message": "The given data was invalid.",
    "errors": {
        "phone_number": [
            "The phone number field is required."
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Register

<mark style="color:green;">`POST`</mark> `https://multiply.arbre.in/api/register`

This endpoint will create a user from given data and also generate an OTP to verify valid phone number.

#### Headers

| Name   | Type   | Description      |
| ------ | ------ | ---------------- |
| Accept | string | application/json |

#### Request Body

| Name          | Type    | Description                   |
| ------------- | ------- | ----------------------------- |
| terms         | integer | 1                             |
| name          | string  | full name                     |
| dob           | string  | yyyy-mm-dd                    |
| gender        | string  | male/female/prefer not to say |
| email         | string  | unique email                  |
| phone\_number | string  | unique phone number           |

{% tabs %}
{% tab title="202 " %}

```
{
    "status": true,
    "token": "8930",
    "message": "OTP generated",
    "data": {
        "name": "MrinmaiSharma",
        "dob": "1997-12-15",
        "gender": "male",
        "email": "mrinmai@arbre.in",
        "phone_number": "7399479451",
        "role": "user",
        "username": "mrinmaisharma1",
        "updated_at": "2021-10-02T11:50:13.000000Z",
        "created_at": "2021-10-02T11:50:13.000000Z",
        "id": 3,
        "profile_photo_url": "https://ui-avatars.com/api/?name=MrinmaiSharma&color=7F9CF5&background=EBF4FF"
    }
}
```

{% endtab %}

{% tab title="422 " %}

```
{
    "message": "The given data was invalid.",
    "errors": {
        "name": [
            "The name field is required."
        ],
        "dob": [
            "The dob field is required."
        ],
        "gender": [
            "The gender field is required."
        ],
        "phone_number": [
            "The phone number field is required."
        ],
        "terms": [
            "The terms field is required."
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Verify OTP

<mark style="color:green;">`POST`</mark> `https://multiply.arbre.in/api/verify-otp`

This endpoint will allow you to validate an OTP for a given phone number

#### Headers

| Name   | Type   | Description      |
| ------ | ------ | ---------------- |
| Accept | string | application/json |

#### Request Body

| Name          | Type   | Description             |
| ------------- | ------ | ----------------------- |
| phone\_number | string | user's phone number     |
| otp           | string | OTP entered by the user |

{% tabs %}
{% tab title="202 " %}

```
{
    "status": true,
    "accessToken": "2|eiSgXjGLzJgWDWEpOrQP9Zz70cFvYRS5LGcVrAde"
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "status": false,
    "message": "OTP is not valid"
}
```

{% endtab %}
{% endtabs %}
