# Authentication

## Login

<mark style="color:green;">`POST`</mark> `https://example.com/api/login`

This endpoint allows you to authenticate a user using **email** and **password**.\
\
After **successful authentication**, you will receive an **access token** which you can use for authentication of other endpoints

#### Headers

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

#### Request Body

| Name     | Type   | Description      |
| -------- | ------ | ---------------- |
| email    | string | Email of user    |
| password | string | Password of user |

{% tabs %}
{% tab title="202 Success fully authenticated" %}

```javascript
{
    "accessToken": "7|vC2gUQC8ajaMOa2juAnaiE4ZLgmH5dcbCDY8Hwsy"
}
```

{% endtab %}

{% tab title="400 Incorrect password" %}

```javascript
{
    "message": "Incorrect password"
}
```

{% endtab %}

{% tab title="404 Email does not exist" %}

```javascript
{
    "message": "User not found"
}
```

{% endtab %}

{% tab title="422 missing fields" %}

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

{% endtab %}
{% endtabs %}

## Logout

<mark style="color:green;">`POST`</mark> `https://example.com/api/logout`

This endpoint will destroy the token for the current user in the server so that any future request with the same token cannot be made.&#x20;

#### Headers

| Name          | Type   | Description                                        |
| ------------- | ------ | -------------------------------------------------- |
| Authorization | string | Bearer 7\|vC2gUQC8ajaMOa2juAnaiE4ZLgmH5dcbCDY8Hwsy |
| Accept        | string | application/json                                   |

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

```javascript
{
    "message": "logged out successfully"
}
```

{% endtab %}

{% tab title="401 Invalid token or token not provided" %}

```javascript
{
    "message": "Unauthenticated."
}
```

{% endtab %}
{% endtabs %}
