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

# Logout

> Logs out the currently authenticated user by invalidating their session token.   Requires a valid authentication token. After calling this endpoint remove the user data from the client.


Logout the current user by invalidating their session token. Requires a valid authentication token. After calling this endpoint remove the user data from the client.

## Request

### Headers

| Name          | Type   | Required | Description  |
| ------------- | ------ | -------- | ------------ |
| Authorization | string | Yes      | Bearer token |

## Response

### 200 OK - Successfully logged out

```json theme={null}
{
  "message": "Successfully logged out John Doe",
  "data": {}
}
```

### 401 Unauthorized

```json theme={null}
{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Missing or invalid authentication token"
  }
}
```

### 500 Internal Server Error

```json theme={null}
{
  "error": {
    "code": "SERVER_ERROR",
    "message": "Internal server error"
  }
}
```

## Example

```bash theme={null}
curl -X POST 'http://localhost:2000/auth/logout' \
  -H 'Authorization: Bearer your-jwt-token'
```

## Notes

* This endpoint requires a valid JWT token in the Authorization header
* The server will invalidate the session token, making it unusable for future requests
* After successful logout, remove all user data from client-side storage
* Clear any stored tokens, user information, or session data from your application
* The response includes a personalized message with the user's name
* This is the recommended way to properly log out users from the system

## Client-side Implementation

After calling this endpoint, you should:

1. Remove the JWT token from storage (localStorage, sessionStorage, cookies)
2. Clear user data from your application state
3. Redirect the user to the login page
4. Clear any cached data that requires authentication

```javascript theme={null}
// Example client-side logout implementation
async function logout() {
  try {
    const response = await fetch('http://localhost:2000/auth/logout', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });
    
    // Clear client-side data
    localStorage.removeItem('authToken');
    localStorage.removeItem('userData');
    
    // Redirect to login
    window.location.href = '/login';
  } catch (error) {
    console.error('Logout failed:', error);
  }
}
```


## OpenAPI

````yaml POST /auth/logout
openapi: 3.0.3
info:
  title: COMPASS API
  version: 1.0.0
  description: OpenAPI specification for the Compass backend routes.
servers:
  - url: http://localhost:2000
    description: Local development server
security: []
tags:
  - name: Auth
    description: >-
      Authentication and session management endpoints (OAuth and session
      validation)
  - name: Users
    description: Operations for managing user records
  - name: Departments
    description: Operations for managing departments
  - name: Email Meter
    description: APIs to get Email Meter Stats
  - name: HubSpot Tickets
    description: Feedback APIs
  - name: Permissions
    description: Permissions APIs
  - name: Transcription
    description: Transcription APIs
paths:
  /auth/logout:
    post:
      tags:
        - Auth
      summary: Logout the current user
      description: >
        Logs out the currently authenticated user by invalidating their session
        token.   Requires a valid authentication token. After calling this
        endpoint remove the user data from the client.
      responses:
        '200':
          description: Successfully logged out user
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Successfully logged out John Doe
                  data:
                    type: object
        '401':
          description: Unauthorized (missing/invalid token)
        '500':
          description: Server error
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````