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 checks its active perks:
suspend fun hasPerk(perkId: String): Boolean {
val person = voidhash.getCurrentPerson() ?: return false
return person.activePerkIds.contains(perkId)
}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:
try {
val hasAccess = hasPerk("premium")
// Route to premium content or the upgrade prompt based on hasAccess.
} catch (error: VoidhashException) {
// 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:
val person = voidhash.getCurrentPerson()The call returns null when no person exists yet for this identity. The snapshot contains
entitlements, subscription state, and purchase history.
Grant fields
Each entry in entitlements.grants has these fields.
| Field | Meaning |
|---|---|
perkId | The perk slug configured in Studio. |
status | active or expired. |
source | subscription, purchase, or manual. |
sourceId | The subscription, purchase, or manual grant that created it. |
expiresAt | Expiration 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:
voidhash.getCurrentPerson(forceFetch = true)