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

# Login

> Authenticate with username/password and return a JWT.

The ``username`` field also accepts an email address for convenience.
Local users must have verified their email before they can log in.

Args:
    payload: Login credentials (username or email, password, captcha token).
    request: The raw HTTP request for IP extraction.
    db:      Database session.

Returns:
    A ``TokenResponse`` with the JWT, expiry, and user profile.

Raises:
    HTTPException 400: CAPTCHA failure.
    HTTPException 401: Invalid credentials.
    HTTPException 403: Account disabled or email not verified.



## OpenAPI

````yaml /openapi.json post /api/auth/login
openapi: 3.1.0
info:
  title: HAI-Co² API
  description: Human-AI Co-Construction reference implementation.
  version: 0.1.0
servers:
  - url: https://haico.gr
    description: Production
  - url: https://dev.haico.gr
    description: Development
  - url: http://localhost:8000
    description: Local development
security: []
paths:
  /api/auth/login:
    post:
      tags:
        - Auth
      summary: Login
      description: |-
        Authenticate with username/password and return a JWT.

        The ``username`` field also accepts an email address for convenience.
        Local users must have verified their email before they can log in.

        Args:
            payload: Login credentials (username or email, password, captcha token).
            request: The raw HTTP request for IP extraction.
            db:      Database session.

        Returns:
            A ``TokenResponse`` with the JWT, expiry, and user profile.

        Raises:
            HTTPException 400: CAPTCHA failure.
            HTTPException 401: Invalid credentials.
            HTTPException 403: Account disabled or email not verified.
      operationId: login_api_auth_login_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoginRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    LoginRequest:
      properties:
        username:
          type: string
          title: Username
        password:
          type: string
          title: Password
        captcha_token:
          type: string
          title: Captcha Token
          default: ''
      type: object
      required:
        - username
        - password
      title: LoginRequest
      description: Login request payload. ``username`` also accepts an email address.
    TokenResponse:
      properties:
        access_token:
          type: string
          title: Access Token
        token_type:
          type: string
          title: Token Type
          default: bearer
        expires_in:
          type: integer
          title: Expires In
        user:
          $ref: '#/components/schemas/UserResponse'
      type: object
      required:
        - access_token
        - expires_in
        - user
      title: TokenResponse
      description: JWT access-token response returned after successful authentication.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    UserResponse:
      properties:
        id:
          type: integer
          title: Id
        username:
          type: string
          title: Username
        email:
          anyOf:
            - type: string
            - type: 'null'
          title: Email
        role:
          type: string
          title: Role
        is_approved:
          type: boolean
          title: Is Approved
        auth_provider:
          type: string
          title: Auth Provider
        email_verified:
          type: boolean
          title: Email Verified
        created_at:
          type: string
          format: date-time
          title: Created At
        recording_consent_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Recording Consent At
        research_publish_consent_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Research Publish Consent At
        email_updates_opt_in:
          type: boolean
          title: Email Updates Opt In
          default: false
      type: object
      required:
        - id
        - username
        - role
        - is_approved
        - auth_provider
        - email_verified
        - created_at
      title: UserResponse
      description: Public user profile returned by auth endpoints.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````