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

# Login

> Authenticate a user and return JWT tokens.

Validates the user's credentials against the specified account and returns
JWT tokens for authenticated access.

Flow:
1. Resolve account by slug or ID
2. Look up user by email in account
3. Check authentication provider (OAuth/SAML users must use their respective flows)
4. Verify password using timing-safe comparison
5. Check if user is active
6. Update last_login timestamp
7. Generate JWT tokens
8. Return response

Security:
- All authentication failures return the same generic 401 message
- Password verification is always performed (even with dummy hash) to prevent timing attacks



## OpenAPI

````yaml post /api/v1/auth/login
openapi: 3.1.0
info:
  title: SnackBase
  description: Open-source Backend-as-a-Service (BaaS)
  version: 0.1.0
servers: []
security: []
paths:
  /api/v1/auth/login:
    post:
      tags:
        - auth
      summary: Login
      description: >-
        Authenticate a user and return JWT tokens.


        Validates the user's credentials against the specified account and
        returns

        JWT tokens for authenticated access.


        Flow:

        1. Resolve account by slug or ID

        2. Look up user by email in account

        3. Check authentication provider (OAuth/SAML users must use their
        respective flows)

        4. Verify password using timing-safe comparison

        5. Check if user is active

        6. Update last_login timestamp

        7. Generate JWT tokens

        8. Return response


        Security:

        - All authentication failures return the same generic 401 message

        - Password verification is always performed (even with dummy hash) to
        prevent timing attacks
      operationId: login_api_v1_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/AuthResponse'
        '401':
          description: Invalid credentials
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    LoginRequest:
      properties:
        account:
          anyOf:
            - type: string
              minLength: 1
            - type: 'null'
          title: Account
          description: >-
            Account identifier (slug or ID in XX#### format). Required in
            multi-tenant mode.
        email:
          type: string
          format: email
          title: Email
          description: User's email address
        password:
          type: string
          minLength: 1
          title: Password
          description: User's password
      type: object
      required:
        - email
        - password
      title: LoginRequest
      description: Request body for user login.
    AuthResponse:
      properties:
        token:
          type: string
          title: Token
          description: JWT access token
        refresh_token:
          type: string
          title: Refresh Token
          description: JWT refresh token
        expires_in:
          type: integer
          title: Expires In
          description: Access token expiration time in seconds
        account:
          $ref: '#/components/schemas/AccountResponse'
          description: Account information
        user:
          $ref: >-
            #/components/schemas/snackbase__infrastructure__api__schemas__auth_schemas__UserResponse
          description: User information
      type: object
      required:
        - token
        - refresh_token
        - expires_in
        - account
        - user
      title: AuthResponse
      description: Response for successful authentication (login).
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    AccountResponse:
      properties:
        id:
          type: string
          title: Id
          description: Account ID in XX#### format
        slug:
          type: string
          title: Slug
          description: URL-friendly account identifier
        name:
          type: string
          title: Name
          description: Display name for the account
        created_at:
          type: string
          format: date-time
          title: Created At
          description: When the account was created
      type: object
      required:
        - id
        - slug
        - name
        - created_at
      title: AccountResponse
      description: Account information in auth responses.
    snackbase__infrastructure__api__schemas__auth_schemas__UserResponse:
      properties:
        id:
          type: string
          title: Id
          description: User ID
        email:
          type: string
          title: Email
          description: User's email address
        role:
          type: string
          title: Role
          description: User's role name
        is_active:
          type: boolean
          title: Is Active
          description: Whether the user is active
        created_at:
          type: string
          format: date-time
          title: Created At
          description: When the user was created
      type: object
      required:
        - id
        - email
        - role
        - is_active
        - created_at
      title: UserResponse
      description: User information in auth responses.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````