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

> ## Agent Instructions
> Treat these docs and the Whop MCP server as the source of truth for Whop API behavior. Don't infer endpoint behavior from marketing pages.
> MCP server: connect https://mcp.whop.com/mcp (streamable HTTP, browser sign-in, no API key in the client config) to search these docs and read or change live Whop data. Setup: https://docs.whop.com/developer/guides/ai_and_mcp.md
> Whop CLI: install with `curl -fsSL https://whop.com/install.sh | sh` to scaffold, run, and deploy Whop apps and websites. It acts on production, not the sandbox. Overview: https://docs.whop.com/cli/overview.md Agent mode: https://docs.whop.com/cli/agent-mode.md
> Hosting: Whop serves a site or app from the build `whop apps deploy` uploads, with rollbacks, secrets, and server logs. Guide: https://docs.whop.com/developer/websites/hosting.md
> Plugins: in Claude Code, run `/plugin marketplace add whopio/plugins`, then `/plugin install whop@whop`. Guide: https://docs.whop.com/developer/guides/plugins/claude-code.md Every agent tool: https://docs.whop.com/developer/ai/overview.md
> Environments: build and test in the sandbox (API `https://sandbox-api.whop.com/api/v1`, keys at https://sandbox.whop.com/dashboard/developer, SDK environment `Sandbox`; no real money). Production (API `https://api.whop.com/api/v1`, keys at https://whop.com/dashboard/developer, SDK environment `Production`, the SDK default) moves real money, so use it only at launch. The two share no accounts, keys, products, or webhooks, and their keys look identical: never mix them. Sandbox guide: https://docs.whop.com/developer/guides/sandbox.md Comparison: https://docs.whop.com/developer/quickstart.md
> API: send `Authorization: Bearer <API_KEY>` from your server only, and pin a dated version with the `Api-Version-Date` header. OpenAPI spec: https://api.whop.com/api/v1/openapi.json
> Which API: build on the Current API, whose pages live under https://docs.whop.com/api-reference/ (start at https://docs.whop.com/api-reference/overview.md). Pages under /api-reference/legacy/ are the Legacy API. Use one only when https://docs.whop.com/api-reference/stability.md lists the resource as Legacy-only.

# Rechten controleren

> Scherm premium iOS-content af met hasAccess(to:) of isSubscribed, toon actieve lidmaatschappen, log gebruikers in en uit om apparaten te synchroniseren en ondersteun aankopen als gast.

Deze gids laat zien hoe je controleert of een gebruiker een actief abonnement heeft en premiumcontent daarop afschermt. Je leert ook hoe je het in- en uitloggen van gebruikers afhandelt om abonnementen tussen apparaten te synchroniseren.

## Wat je leert

* Controleren of een gebruiker toegang heeft tot een product
* Content afschermen op basis van de abonnementsstatus
* Abonnementen tussen apparaten synchroniseren met gebruikerslogin

## Vereisten

* [Installeer de SDK](https://docs.whop.com/nl/developer/guides/ios/installation.md)
* [Configureer de SDK](https://docs.whop.com/nl/developer/guides/ios/build-a-paywall.md#step-1-configure-the-sdk)

## Abonnementsstatus controleren

Gebruik `hasAccess(to:)` om te controleren of de gebruiker toegang heeft tot een specifiek product:

```swift theme={null}
struct ContentView: View {
    @Environment(Checkout.self) var checkout

    var body: some View {
        VStack {
            // Basic features always available
            BasicFeaturesView()

            // Premium features for subscribers
            if checkout.hasAccess(to: "prod_xxxxxxxxxxxxxx") {
                PremiumFeaturesView()
            }

            // If you have multiple tiers, check each product separately
            if checkout.hasAccess(to: "prod_yyyyyyyyyyyyyy") {
                EnterpriseFeaturesView()
            }
        }
    }
}
```

Of gebruik `isSubscribed` om te controleren of de gebruiker een actief abonnement heeft:

```swift theme={null}
if checkout.isSubscribed {
    // User has at least one active membership
}
```

## Actieve lidmaatschappen bekijken

Gebruik de array `memberships` om abonnementsgegevens te tonen:

```swift theme={null}
struct SubscriptionStatusView: View {
    @Environment(Checkout.self) var checkout

    var body: some View {
        List {
            if checkout.memberships.isEmpty {
                Text("No active subscriptions")
                    .foregroundStyle(.secondary)
            } else {
                ForEach(checkout.memberships) { membership in
                    MembershipRow(membership: membership)
                }
            }
        }
    }
}

struct MembershipRow: View {
    let membership: CheckoutMembership

    var body: some View {
        VStack(alignment: .leading) {
            Text("Subscription")
                .font(.headline)

            if let expiresAt = membership.expiresAt {
                Text("Renews \(expiresAt, style: .date)")
                    .foregroundStyle(.secondary)
            }

            Text("Status: \(membership.status.rawValue)")
                .font(.caption)
                .foregroundStyle(.secondary)
        }
    }
}
```

## Gebruikers in- en uitloggen

Met gebruikers-ID's worden abonnementen tussen apparaten gesynchroniseerd. Wanneer een gebruiker inlogt, claimt de SDK automatisch alle niet-geclaimde lidmaatschappen van het huidige apparaat en laadt de bestaande lidmaatschappen van de gebruiker.

### Een gebruiker inloggen

```swift theme={null}
func handleLogin(userId: String) async {
    do {
        try await checkout.logIn(appUserId: userId)
        // Memberships are now synced for this user
    } catch {
        print("Login failed: \(error)")
    }
}
```

### Een gebruiker uitloggen

```swift theme={null}
func handleLogout() {
    checkout.logOut()
    // User is now logged out, memberships cleared
}
```

### De huidige gebruiker controleren

```swift theme={null}
if let userId = checkout.appUserId {
    Text("Logged in as \(userId)")
} else {
    Text("Not logged in")
}
```

## Aankopen als gast

Gebruikers kunnen abonnementen kopen zonder in te loggen. De SDK houdt deze aankopen bij op basis van het apparaat-ID en claimt ze automatisch wanneer de gebruiker inlogt.

```swift theme={null}
struct PurchaseFlow: View {
    @Environment(Checkout.self) var checkout
    @State private var showingLogin = false

    var body: some View {
        VStack {
            if checkout.appUserId == nil {
                // User not logged in - they can still purchase
                Text("Purchase as guest or log in to sync across devices")

                Button("Continue as Guest") {
                    // Purchase will be tied to device
                    Task { try? await checkout.purchase("plan_xxx") }
                }

                Button("Log In") {
                    showingLogin = true
                }
            } else {
                // User logged in - purchase tied to their account
                Button("Subscribe") {
                    Task { try? await checkout.purchase("plan_xxx") }
                }
            }
        }
        .sheet(isPresented: $showingLogin) {
            // Your login view here
        }
    }
}
```

## Compleet voorbeeld

Hier is een compleet voorbeeld van het controleren van rechten met gebruikersauthenticatie:

```swift theme={null}
struct MainView: View {
    @Environment(Checkout.self) var checkout
    @State private var showingPaywall = false
    @State private var showingLogin = false

    var body: some View {
        NavigationStack {
            Group {
                if !checkout.isInitialized {
                    ProgressView("Loading...")
                } else if checkout.hasAccess(to: "prod_xxxxxxxxxxxxxx") {
                    PremiumContentView()
                } else {
                    FreeContentView(onUpgrade: { showingPaywall = true })
                }
            }
            .toolbar {
                ToolbarItem(placement: .topBarTrailing) {
                    Menu {
                        if let userId = checkout.appUserId {
                            Text("Signed in as \(userId)")
                            Button("Sign Out", action: signOut)
                        } else {
                            Button("Sign In") { showingLogin = true }
                        }

                        Divider()

                        if checkout.hasAccess(to: "prod_xxxxxxxxxxxxxx") {
                            Button("Manage Subscription") {
                                // Show subscription management
                            }
                        }
                    } label: {
                        Image(systemName: "person.circle")
                    }
                }
            }
            .sheet(isPresented: $showingPaywall) {
                PaywallView()
            }
            .sheet(isPresented: $showingLogin) {
                LoginView { userId in
                    Task {
                        try? await checkout.logIn(appUserId: userId)
                        showingLogin = false
                    }
                }
            }
        }
    }

    func signOut() {
        checkout.logOut()
    }
}

struct FreeContentView: View {
    let onUpgrade: () -> Void

    var body: some View {
        VStack(spacing: 20) {
            Text("Free Content")
                .font(.title)

            Text("Upgrade to access premium features")
                .foregroundStyle(.secondary)

            Button("Upgrade Now", action: onUpgrade)
                .buttonStyle(.borderedProminent)
        }
    }
}

struct PremiumContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "crown.fill")
                .font(.largeTitle)
                .foregroundStyle(.yellow)

            Text("Premium Content")
                .font(.title)

            Text("Thanks for subscribing!")
        }
    }
}
```

## Reactieve updates

De SDK werkt weergaven automatisch bij wanneer de abonnementsstatus verandert. Omdat `Checkout` `@Observable` is, wordt elke weergave die `@Environment(Checkout.self)` gebruikt opnieuw gerenderd wanneer:

* Een aankoop is voltooid
* Een gebruiker in- of uitlogt
* De SDK lidmaatschappen laadt of bijwerkt

Je hoeft niet handmatig te vernieuwen.

## Volgende stappen

> [card] [Een paywall bouwen](https://docs.whop.com/nl/developer/guides/ios/build-a-paywall.md)
>
> Toon varianten en verwerk aankopen

> [card] [API-referentie](https://docs.whop.com/nl/developer/guides/ios/checkout-reference.md)
>
> Verken alle beschikbare methoden en eigenschappen


## Related topics

- [iOS Checkout SDK](https://docs.whop.com/nl/developer/guides/ios/overview.md)
- [Een iOS-paywall bouwen](https://docs.whop.com/nl/developer/guides/ios/build-a-paywall.md)
- [Referentie voor de iOS Checkout SDK](https://docs.whop.com/nl/developer/guides/ios/checkout-reference.md)
