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

# Leave Organization

> Allows a user to leave an organization. Cannot leave if the user is the last owner.



## OpenAPI

````yaml POST /auth/leave-org
openapi: 3.0.0
info:
  title: ClosedVPN API
  version: 1.1.0
  description: >
    API for managing authentication, organizations, members, VPN configurations,

    certificates and usage reporting for the ClosedVPN platform.


    The VPN capability previously delivered through the OneFirewall Application

    (`https://app.onefirewall.com/api/v1/vpn`) now runs on ClosedVPN and is
    served

    from `https://closedvpn.io`. The legacy OneFirewall VPN endpoints are
    deprecated

    and replaced by the operations documented here.


    Most endpoints require a Personal Access Token (PAT), sent as

    `Authorization: Bearer <pat>`. To obtain one, sign in through the magic link

    flow (`/auth/send-magic-link` then `/auth/verify-magic-link`, neither of
    which

    requires prior authentication) and then call `/auth/generate-pat`, or create
    the

    token from the Profile page in the web application. The plaintext token is
    shown

    only once and is stored as a bcrypt hash, so it cannot be recovered later.
  contact:
    name: OneFirewall Alliance
    url: https://closedvpn.io
    email: support@onefirewall.com
servers:
  - url: https://closedvpn.io
    description: Production server
security: []
tags:
  - name: Authentication
    description: Magic link sign-in, session validation and sign-out.
  - name: Profile
    description: Read and update the authenticated user's profile.
  - name: Personal Access Tokens
    description: Create, list and revoke Personal Access Tokens used for API access.
  - name: Organizations
    description: Create, update, list, select and delete organizations.
  - name: Members
    description: Add members to an organization, change their role and remove them.
  - name: VPN Certificates
    description: Issue and download the OpenVPN client profile for a member.
  - name: VPN Configurations
    description: Manage VPN server configurations and run their predefined commands.
  - name: VPN Exit Nodes
    description: List the VPN exit nodes available to the caller.
  - name: Statistics
    description: Connection status, traffic reporting and threat prevention metrics.
  - name: Notifications
    description: Read in-app notifications and mark them as read.
  - name: Activity Logs
    description: Retrieve the caller's recent activity.
paths:
  /auth/leave-org:
    post:
      tags:
        - Members
      summary: Leave an organization
      description: >-
        Allows a user to leave an organization. Cannot leave if the user is the
        last owner.
      operationId: leaveOrganization
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                org_id:
                  type: string
                  example: 60c72b2f5f1b2c001c8e4b1a
              required:
                - org_id
      responses:
        '200':
          description: Left organization successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: You have successfully left the organization
                  orgs:
                    type: array
                    description: >
                      The caller's remaining organizations. If this was their
                      only organization, a new default organization is created
                      and returned here.
                    items:
                      $ref: '#/components/schemas/Organization'
        '400':
          description: Missing organization ID
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Organization ID is required
        '401':
          description: Unauthorized (invalid or missing PAT)
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Unauthorized
        '403':
          description: Forbidden (cannot leave as the last owner)
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: >-
                      Cannot leave as the last owner. Add another owner or
                      delete the organization.
        '404':
          description: Organization or user not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Organization not found
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Error leaving organization
      security:
        - bearerAuth: []
components:
  schemas:
    Organization:
      type: object
      properties:
        _id:
          type: string
          example: 60c72b2f5f1b2c001c8e4b1a
        name:
          type: string
          example: My Org
        description:
          type: string
          example: Default organization
        org_avatar:
          type: string
          example: data:image/svg+xml;base64,...
          description: Base64-encoded SVG identicon, or a caller-supplied image URL
        active:
          type: boolean
          example: true
        users:
          type: array
          items:
            $ref: '#/components/schemas/OrgUser'
        vpn_id:
          type: string
          nullable: true
          description: ObjectId of the VPN configuration assigned to this organization
          example: 60c72b2f5f1b2c001c8e4b2a
        vpn_name:
          type: string
          description: Name of the assigned VPN, or "No VPN Assigned" if none is set
          example: Frankfurt Node
        used_licenses:
          type: integer
          description: Number of certificates issued in this organization
          example: 3
        total_licenses:
          type: integer
          description: Maximum number of certificates this organization may issue
          example: 10
        createdAt:
          type: integer
          format: int64
          description: Creation time as Unix epoch milliseconds
          example: 1735689600000
    OrgUser:
      type: object
      properties:
        user_id:
          type: string
          nullable: true
          description: >
            ObjectId of the member's user record, or null if they have been
            added but have not yet signed in for the first time.
          example: 60c72b2f5f1b2c001c8e4b1b
        email:
          type: string
          format: email
          example: john@example.com
        name:
          type: string
          example: John Doe
        user_avatar:
          type: string
          example: JD
          description: Initials or avatar representation
        role:
          type: string
          enum:
            - owner
            - member
          example: owner
        active:
          type: boolean
          description: False once the member has been removed or has left the organization
          example: true
        invitation:
          type: object
          properties:
            status:
              type: string
              enum:
                - completed
              example: completed
              description: >-
                Members are activated immediately; there is no accept or decline
                step
            createdAt:
              type: integer
              format: int64
              nullable: true
              description: >-
                Unix epoch milliseconds, or null if the member has not signed in
                yet
              example: 1735689600000
        hasCertificate:
          type: boolean
          description: >
            Whether a VPN certificate has been issued to this member. The
            certificate itself is never returned by organization endpoints.
          example: true
        membership_periods:
          type: array
          description: >-
            Join and leave timestamps across the member's history in this
            organization
          items:
            type: object
            properties:
              joinedAt:
                type: integer
                format: int64
                nullable: true
                example: 1735689600000
              leftAt:
                type: integer
                format: int64
                nullable: true
                description: Null while the membership is still open
                example: null
        createdAt:
          type: integer
          format: int64
          description: Unix epoch milliseconds
          example: 1735689600000
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: PAT
      description: >
        Personal Access Token (PAT) passed in the Authorization header (e.g.,
        `Bearer <pat>`) for authenticated API requests. PATs are generated via
        `/auth/generate-pat` after authenticating through the magic link flow.

````