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

# Switch Organization

> Switch to a different organization that the user belongs to. This endpoint revokes the current token and generates a new access token for the target organization.

**Requirements:**
- User must be authenticated
- Target user must belong to the same email as current user
- Target organization must be active

**Note:** After switching, the previous access token is revoked. You must use the new token returned in the response.



## OpenAPI

````yaml /openapi/public/openapi-auth.json post /organization/switch
openapi: 3.0.0
info:
  title: MileApp API - Auth
  version: 3.0.0
  description: MileApp API Documentation - RESTful API for field operations management.
servers:
  - url: https://apiweb.mile.app/api/v3
security:
  - bearerAuth: []
tags:
  - name: Multi-Organization
    description: >-
      Multi-Organization feature allows users to belong to multiple
      organizations using the same email address. This enables seamless
      switching between organizations without requiring separate login
      credentials. When a user logs in with an email associated with multiple
      organizations, they can select which organization to access and switch
      between them with password verification only.


      **Related Guide:** [User
      Management](https://doc.mile.app/pages/setting/user-management/introduction-to-user-management)
paths:
  /organization/switch:
    post:
      tags:
        - Multi-Organization
      summary: Switch Organization
      description: >-
        Switch to a different organization that the user belongs to. This
        endpoint revokes the current token and generates a new access token for
        the target organization.


        **Requirements:**

        - User must be authenticated

        - Target user must belong to the same email as current user

        - Target organization must be active


        **Note:** After switching, the previous access token is revoked. You
        must use the new token returned in the response.
      operationId: switchOrganization
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - targetUserId
              properties:
                targetUserId:
                  type: string
                  description: >-
                    The user ID to switch to. This can be obtained from the
                    organizations array returned by Get User Organizations
                    endpoint.
              example:
                targetUserId: 507f1f77bcf86cd799439012
        required: true
      responses:
        '200':
          description: Switch successful - returns new access token and user data
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: string
                    description: New access token for the target organization
                  expires_in:
                    type: integer
                    description: Token expiration time in seconds
                  data:
                    type: object
                    description: User data for the target organization
                    additionalProperties: true
                  isHubSet:
                    type: boolean
                    description: Whether user has hub assigned in the target organization
                  organizations:
                    type: array
                    description: Updated list of all user's organizations
                    items:
                      type: object
                      properties:
                        userId:
                          type: string
                        organizationId:
                          type: string
                        organizationName:
                          type: string
                        organizationLogo:
                          type: string
                        roleName:
                          type: string
                        isCurrent:
                          type: boolean
                example:
                  token: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...
                  expires_in: 31536000
                  data:
                    _id: 507f1f77bcf86cd799439012
                    name: John Doe
                    email: john@example.com
                    organizationId: 507f1f77bcf86cd799439023
                  isHubSet: true
                  organizations:
                    - userId: 507f1f77bcf86cd799439011
                      organizationId: 507f1f77bcf86cd799439022
                      organizationName: Acme Corp
                      organizationLogo: https://storage.mile.app/logos/acme.png
                      roleName: owner
                      isCurrent: false
                    - userId: 507f1f77bcf86cd799439012
                      organizationId: 507f1f77bcf86cd799439023
                      organizationName: Beta Inc
                      organizationLogo: null
                      roleName: admin
                      isCurrent: true
        '400':
          description: Bad request - Account not active or organization not active
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
                example:
                  status: false
                  message: Account is not active
        '403':
          description: Forbidden - Invalid organization selection
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
                example:
                  status: false
                  message: Invalid organization selection
      deprecated: false
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Use a valid Bearer token to authenticate.

````