# Clerk

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

## Access user state

Use `Clerk.userFlow` to reactively observe the current user:

```kotlin
import com.clerk.api.Clerk

// In a ViewModel or Composable
val user by Clerk.userFlow.collectAsState(initial = null)

if (user != null) {
    Text("Welcome, ${user.firstName}")
} else {
    Text("Please sign in")
}
```

## Access the Clerk instance

Access authentication methods through the global `Clerk` object:

```kotlin
import com.clerk.api.Clerk

// Sign in
Clerk.auth.signInWithPassword {
    identifier = "user@email.com"
    password = "secretpassword"
}

// Sign out
Clerk.auth.signOut()
```

## 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 null 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.organizationIsEnabled                 | Boolean                 | Whether Organizations are enabled for the instance.                                                                                                                                                                                                                                                                                                                                                                                                                |
| Clerk.organizationSelectionIsForced         | Boolean                 | Whether users must choose an Organization before the session is considered complete.                                                                                                                                                                                                                                                                                                                                                                               |
| Clerk.organizationDomainsIsEnabled          | Boolean                 | Whether Verified Domains are enabled for Organizations.                                                                                                                                                                                                                                                                                                                                                                                                            |
| Clerk.organizationDomainEnrollmentModes     | List<String>           | The enabled Organization domain enrollment modes.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| Clerk.organizationCreationDefaultsIsEnabled | Boolean                 | Whether Organization creation defaults are enabled for the current user.                                                                                                                                                                                                                                                                                                                                                                                           |
| Clerk.organizationAdminDeleteIsEnabled      | Boolean                 | Whether Organization admins can delete Organizations from the client.                                                                                                                                                                                                                                                                                                                                                                                              |
| Clerk.organizationSlugIsEnabled             | Boolean                 | Whether Organization slugs are enabled for the instance.                                                                                                                                                                                                                                                                                                                                                                                                           |

```kotlin
val activeOrganization = Clerk.organization
val activeMembership = Clerk.organizationMembership
val 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 `null`) to select the user's Personal Account. The latter isn't allowed when `Clerk.organizationSelectionIsForced` is `true`.

### Select an Organization

```kotlin
val sessionId = Clerk.session?.id ?: return

when (
    val result = Clerk.auth.setActive(
        sessionId = sessionId,
        organizationId = "org_123",
    )
) {
    is ClerkResult.Success -> {
        val session = result.value
    }
    is ClerkResult.Failure -> {
        // Handle the failure.
    }
}
```

### Select the Personal Account

```kotlin
val sessionId = Clerk.session?.id ?: return

when (val result = Clerk.auth.setActive(sessionId = sessionId)) {
    is ClerkResult.Success -> {
        val personalAccountSession = result.value
    }
    is ClerkResult.Failure -> {
        // Handle the failure.
    }
}
```

---

## Sitemap

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