# Clerk

`Clerk` is the main entry point for the SDK. After you [configure the SDK](https://clerk.com/docs/ios/reference/native-mobile/configuration.md), you can access it in two ways:

## Access Clerk through SwiftUI

After you inject `Clerk.shared` into the environment, you can access it with `@Environment(Clerk.self)`.

```swift
import ClerkKit
import SwiftUI

struct ContentView: View {
  @Environment(Clerk.self) private var clerk

  var body: some View {
    if clerk.user != nil {
      Text("Signed in")
    } else {
      Text("Signed out")
    }
  }
}
```

## Access Clerk through the shared instance

If you're not using SwiftUI, you can always access Clerk through the shared instance.

```swift
let clerk = Clerk.shared
```

## Access the Active Organization state

When Organizations are enabled, the current session can have an Active Organization. Use these properties to access the current Organization state and its instance settings:

| Name                                                                         | Type                    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ---------------------------------------------------------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| clerk.organization                                                           | Organization?           | The Active OrganizationA user can be a member of multiple Organizations, but only one can be active at a time. The Active Organization determines which Organization-specific data the user can access and which Role and related Permissions they have within the Organization. for the current active session. Returns nil when there is no active session, no selected Organization, or the active user's memberships don't include the selected Organization. |
| clerk.organizationMembership                                                 | OrganizationMembership? | The active user's membership in clerk.organization.                                                                                                                                                                                                                                                                                                                                                                                                               |
| clerk.session?.lastActiveOrganizationId                                      | String?                 | The Organization ID selected on the current session.                                                                                                                                                                                                                                                                                                                                                                                                              |
| clerk.environment?.organizationSettings.enabled                              | Bool?                   | Whether Organizations are enabled for the instance.                                                                                                                                                                                                                                                                                                                                                                                                               |
| clerk.environment?.organizationSettings.forceOrganizationSelection           | Bool?                   | Whether users must choose an Organization before the session is considered complete.                                                                                                                                                                                                                                                                                                                                                                              |
| clerk.environment?.organizationSettings.domains.enabled                      | Bool?                   | Whether Verified Domains are enabled for Organizations.                                                                                                                                                                                                                                                                                                                                                                                                           |
| clerk.environment?.organizationSettings.domains.enrollmentModes              | [String]?              | The enabled Organization domain enrollment modes.                                                                                                                                                                                                                                                                                                                                                                                                                 |
| clerk.environment?.organizationSettings.organizationCreationDefaults.enabled | Bool?                   | Whether Organization creation defaults are enabled for the current user.                                                                                                                                                                                                                                                                                                                                                                                          |
| clerk.environment?.organizationSettings.actions.adminDelete                  | Bool?                   | Whether Organization admins can delete Organizations from the client.                                                                                                                                                                                                                                                                                                                                                                                             |
| clerk.environment?.organizationSettings.slug.disabled                        | Bool?                   | Whether Organization slugs are disabled for the instance.                                                                                                                                                                                                                                                                                                                                                                                                         |

```swift
let activeOrganization = clerk.organization
let activeMembership = clerk.organizationMembership
let activeOrganizationId = clerk.session?.lastActiveOrganizationId

if activeMembership?.canManageMemberships == true {
  // Show organization membership management.
}
```

## Switch the Active Organization

Use `clerk.auth.setActive()` to switch the Active Organization for a session. Pass `sessionId` and `organizationId` to select an Organization, or omit `organizationId` (or pass `nil`) to select the user's Personal Account. The latter isn't allowed when `clerk.environment?.organizationSettings.forceOrganizationSelection` is `true`.

### Select an Organization

```swift
guard let sessionId = clerk.session?.id else { return }

try await clerk.auth.setActive(
  sessionId: sessionId,
  organizationId: "org_123"
)
```

### Select the Personal Account

```swift
guard let sessionId = clerk.session?.id else { return }

try await clerk.auth.setActive(sessionId: sessionId)
```

---

## Sitemap

[Overview of all docs pages](https://clerk.com/docs/llms.txt)
