# /api/organizations/active (dashboard)

Source-derived dashboard endpoint contract, authentication, request validation, responses, and errors.

Source: https://docs.minds.sh/docs/api/platform/reference/dashboard--api-organizations-active



This is the **dashboard** service route. Its origin and authentication are described in [Platform API overview](/docs/api/platform) and [Authentication](/docs/api/platform/authentication). A path shared by another service is a different endpoint.

| Property                       | Contract                                                                       |
| ------------------------------ | ------------------------------------------------------------------------------ |
| Methods                        | POST                                                                           |
| Path                           | `/api/organizations/active`                                                    |
| Path parameters                | None                                                                           |
| Query parameters read in route | None read directly; schema validation below may define additional fields       |
| Headers read in route          | No additional direct header reads; authentication helpers may read credentials |

## Authentication and access [#authentication-and-access]

Dashboard session cookie through @repo/auth/server. Some auth-summary routes can redirect to sign-in; inspect the status branches below.

## Method behavior [#method-behavior]

The handler excerpt preserves field validation, response envelopes, cookie changes, and exception branches. Values returned by service helpers retain their named response type above; for passthrough routes, the upstream response is authoritative.

### POST [#post]

```typescript
export async function POST(request: NextRequest) {
  try {
    const session = await getSession();
    if (!session) {
      return NextResponse.json(
        { error: { code: 'UNAUTHENTICATED', message: 'Sign in at auth.l1fe.ai.' } },
        { status: 401 }
      );
    }

    const body = await request.json();
    const organizationId = typeof body.organizationId === 'string' ? body.organizationId : null;
    if (!organizationId) {
      return NextResponse.json(
        { error: { code: 'INVALID_REQUEST', message: 'organizationId is required' } },
        { status: 400 }
      );
    }

    const organizations = await listMindsOrganizations({
      accessToken: session.accessToken,
      includeEntitlements: false,
    });
    const organization = organizations.find((item) => item.id === organizationId);
    if (!organization) {
      return NextResponse.json(
        { error: { code: 'ORG_NOT_AVAILABLE', message: 'Organization is not available to Minds.' } },
        { status: 404 }
      );
    }

    const cookieStore = await cookies();
    cookieStore.set(ACTIVE_TENANT_COOKIE, organization.id, {
      httpOnly: true,
      secure: process.env.NODE_ENV === 'production',
      sameSite: 'lax',
      maxAge: COOKIE_MAX_AGE,
      path: '/',
    });

    return NextResponse.json({ success: true, organizationId: organization.id });
  } catch (error) {
    console.error('Failed to set active organization:', error);
    return NextResponse.json(
      {
        error: {
          code: 'SET_FAILED',
          message: error instanceof Error ? error.message : 'Failed to set active organization',
        },
      },
      { status: 500 }
    );
  }
}
```

Source: `minds-ui/apps/app/app/api/organizations/active/route.ts:12`.

## Response and error branches [#response-and-error-branches]

Literal HTTP statuses in the route: 400, 401, 404, 500. Shared management error classes are defined in [Errors and responses](/docs/api/platform/errors).

```typescript
NextResponse.json(
        { error: { code: 'UNAUTHENTICATED', message: 'Sign in at auth.l1fe.ai.' } },
        { status: 401 }
      )
```

Source: `minds-ui/apps/app/app/api/organizations/active/route.ts:16`.

```typescript
request.json()
```

Source: `minds-ui/apps/app/app/api/organizations/active/route.ts:22`.

```typescript
NextResponse.json(
        { error: { code: 'INVALID_REQUEST', message: 'organizationId is required' } },
        { status: 400 }
      )
```

Source: `minds-ui/apps/app/app/api/organizations/active/route.ts:25`.

```typescript
NextResponse.json(
        { error: { code: 'ORG_NOT_AVAILABLE', message: 'Organization is not available to Minds.' } },
        { status: 404 }
      )
```

Source: `minds-ui/apps/app/app/api/organizations/active/route.ts:37`.

```typescript
NextResponse.json({ success: true, organizationId: organization.id })
```

Source: `minds-ui/apps/app/app/api/organizations/active/route.ts:52`.

```typescript
NextResponse.json(
      {
        error: {
          code: 'SET_FAILED',
          message: error instanceof Error ? error.message : 'Failed to set active organization',
        },
      },
      { status: 500 }
    )
```

Source: `minds-ui/apps/app/app/api/organizations/active/route.ts:55`.

## Service dependencies [#service-dependencies]

* `minds-ui/apps/app/lib/organizations.ts`

## Evidence [#evidence]

Generated from the local source snapshot on 2026-09-12. This page documents implemented code and does not certify a deployed service, permissions configuration, or successful provider operation.

Source file: `minds-ui/apps/app/app/api/organizations/active/route.ts`. SHA-256: `46eac39878b990bd2383b2f86b1375e225892f8a9c89501ad0744e571286af0a`.
