Check access

Gate features using the current customer's active perk grants.

Use the current person's active perk grants to decide what a customer can access in your app. The person snapshot also carries subscription state and purchase history, but perk grants are what you gate on.

The SDK decides what to show on the device. It cannot protect anything a customer can reach by calling your API directly. Those checks belong on your server. See Check access from your backend.

Gate a feature

A perk is available when the person holds a grant for it with status active. This helper reads the current person and looks for such a grant:

func hasPerk(_ perkId: String) async throws -> Bool {
    let person = try await voidhash.getCurrentPerson()
    return person?.entitlements.grants.contains {
        $0.perkId == perkId && $0.status == "active"
    } ?? false
}

Wrap the check once in a helper like this so your screens stay simple.

Gate on perks, not subscription status

Subscription status cannot tell you which features a product unlocks. It also misses access that comes from one-time purchases or manual grants. Active perk grants are the source of truth for access control.

Offline and failure behavior

A failed refresh, whether the device is offline or the server returned an error, is not proof that the customer has no access.

getCurrentPerson() throws on failure rather than answering a confident "no". Treat a thrown error as "unknown". Retry, or serve the last state you know about:

do {
    let hasAccess = try await hasPerk("premium")
    // Route to premium content or the upgrade prompt based on hasAccess.
} catch {
    // Unknown. Retry or fall back to cached state. Never lock by default.
}

Read the current person

When you need more than a single perk check, read the full snapshot:

let person = try await voidhash.getCurrentPerson()

The call returns nil when no person exists yet for this identity. The snapshot contains entitlements, subscription state, and purchase history. Filter entitlements.grants yourself when one perk check is not enough.

Grant fields

Each entry in entitlements.grants has these fields.

FieldMeaning
perkIdThe perk slug configured in Studio.
statusactive or expired.
sourcesubscription, purchase, or manual.
sourceIdThe subscription, purchase, or manual grant that created it.
expiresAtExpiration time, or null for access without an expiry.

Use subscriptions.current for account UI, such as the current plan or its renewal state. Use purchases.history when you need to show past transactions.

Refresh behavior

The SDK refreshes the person after purchases, restores, and identity changes. Between refreshes it serves a cached snapshot. The snapshot is cached for two days and is served stale after five minutes. Pass forceFetch: true when you need a network round trip:

try await voidhash.getCurrentPerson(forceFetch: true)

Next steps