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

# Authentication

> How to authenticate with the StartMyVPN API.

## Obtaining a token

Make a POST request to the login endpoint:

```http theme={null}
POST /v1/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "your_password"
}
```

**Success response (200):**

```json theme={null}
{
  "success": true,
  "data": {
    "token": "1|abc123...",
    "user": {
      "id": 1,
      "name": "Jane Smith",
      "email": "user@example.com"
    }
  }
}
```

**Failed authentication (401):**

```json theme={null}
{
  "success": false,
  "message": "Invalid credentials."
}
```

## Using the token

Pass the token as a Bearer header on every protected request:

```http theme={null}
GET /v1/user
Authorization: Bearer 1|abc123...
```

## Token management

Tokens are scoped to a single device. Each login call creates a new token.

**Logout (current device):**

```http theme={null}
POST /v1/auth/logout
Authorization: Bearer {token}
```

**Logout all devices:**

```http theme={null}
POST /v1/auth/logout-all
Authorization: Bearer {token}
```

## Email verification

If email verification is enabled on your StartMyVPN installation, API users must verify their email before accessing protected endpoints.

**Resend verification email:**

```http theme={null}
POST /v1/auth/resend-verification
Authorization: Bearer {token}
```

**Verify email with code:**

```http theme={null}
POST /v1/auth/verify-email
Content-Type: application/json

{
  "token": "verification_token_from_email"
}
```

## Password reset

**Request reset (sends email):**

```http theme={null}
POST /v1/auth/forgot-password
Content-Type: application/json

{
  "email": "user@example.com"
}
```

**Submit new password:**

```http theme={null}
POST /v1/auth/reset-password
Content-Type: application/json

{
  "token": "reset_token_from_email",
  "email": "user@example.com",
  "password": "new_password",
  "password_confirmation": "new_password"
}
```
