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

# Authentication

> Authentication endpoints for user login, registration, and password management

# Authentication

LabTrace uses JWT (JSON Web Tokens) for authentication. All API endpoints except authentication-related ones require a valid JWT token in the Authorization header.

## Authentication Flow

1. **Register** a new user account
2. **Login** with email and password to receive a JWT token
3. **Include** the JWT token in the Authorization header for all subsequent requests
4. **Use** password reset functionality if needed

## Headers

For authenticated requests, include the JWT token in the Authorization header:

```
Authorization: Bearer YOUR_JWT_TOKEN_HERE
```

## Login

<Card title="POST /login" icon="lock">
  Authenticate a user and receive a JWT token
</Card>

### Request Body

```json theme={null}
{
  "email": "user@example.com",
  "password": "your-password"
}
```

### Response

```json theme={null}
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
```

### Example

```bash theme={null}
curl -X POST https://api.labtrace.io/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com", 
    "password": "your-password"
  }'
```

## User Registration

<Card title="POST /users" icon="user-plus">
  Register a new user account
</Card>

### Request Body

```json theme={null}
{
  "name": "John",
  "lastName": "Doe",
  "email": "john.doe@example.com",
  "password": "secure-password",
  "organisation": "Research Institute",
  "location": "New York"
}
```

### Response

```json theme={null}
{
  "info": {
    "statusCode": 200,
    "responseMessage": "User created"
  }
}
```

### Example

```bash theme={null}
curl -X POST https://api.labtrace.io/users \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John",
    "lastName": "Doe",
    "email": "john.doe@example.com",
    "password": "secure-password",
    "organisation": "Research Institute",
    "location": "New York"
  }'
```

## Account Activation

<Card title="GET /users/activation/{token}" icon="check-circle">
  Activate a user account using the token sent via email
</Card>

### Parameters

* `token` (path): Activation token received via email

### Response

```json theme={null}
{
  "info": {
    "statusCode": 200,
    "responseMessage": "Account has been activated."
  }
}
```

## Password Reset

### Request Password Reset

<Card title="GET /users/forgot-password/{email}" icon="key">
  Request a password reset email
</Card>

### Parameters

* `email` (path): User's email address

### Response

```json theme={null}
{
  "info": {
    "statusCode": 200,
    "responseMessage": "Password reset email sent"
  }
}
```

### Reset Password

<Card title="POST /users/reset-password/{token}" icon="lock-open">
  Reset password using the token sent via email
</Card>

### Parameters

* `token` (path): Password reset token received via email

### Request Body

```json theme={null}
{
  "password": "new-secure-password"
}
```

### Response

```json theme={null}
{
  "info": {
    "statusCode": 200,
    "responseMessage": "Password has been changed."
  }
}
```

### Example

```bash theme={null}
curl -X POST https://api.labtrace.io/users/reset-password/RESET_TOKEN \
  -H "Content-Type: application/json" \
  -d '{
    "password": "new-secure-password"
  }'
```

## Error Responses

All authentication endpoints may return the following error responses:

### 400 Bad Request

```json theme={null}
{
  "error": {
    "statusCode": 400,
    "message": "Invalid request parameters"
  }
}
```

### 401 Unauthorized

```json theme={null}
{
  "error": {
    "statusCode": 401,
    "message": "Invalid credentials"
  }
}
```

### 500 Internal Server Error

```json theme={null}
{
  "error": {
    "statusCode": 500,
    "message": "Internal server error"
  }
}
```

## JWT Token Information

JWT tokens contain the following claims:

* `id`: User ID
* `email`: User email
* `iat`: Issued at timestamp
* `exp`: Expiration timestamp

Tokens are valid for 24 hours and will need to be refreshed by logging in again when expired.
