Check access

Gate features on the current person's active perks.

Check access by asking whether the current person has an active perk, such as premium. The person's entitlements list each perk they can use and what granted it; see Products and perks and the subscription lifecycle for when access starts and ends.

The SDK decides what your app shows. It can't protect anything a person reaches through your own API: check access on your server for that, with the server library for Node.js, PHP, Go or Rust, or over HTTP.

Gate a feature

hasActivePerk takes the perk's slug from Studio:

suspend fun hasPremium(): Boolean =
    voidhash.getCurrentPerson()?.hasActivePerk("premium") == true

activePerkSlugs lists every perk the person can use right now.

Caching and offline behavior

getCurrentPerson() answers from a cache and refreshes behind the read. The snapshot is fresh for 5 minutes and kept for 2 days; after that it's still served, marked expired. With nothing cached, the call waits at most 10 seconds for Voidhash. The SDK refreshes the person after purchases, restores, identify and reset. Pass forceFetch = true to wait for a fresh answer:

val person = voidhash.getCurrentPerson(forceFetch = true)

getCurrentPerson() never throws because Voidhash is unreachable. It keeps serving the last snapshot until Voidhash confirms the person doesn't exist. Use getCurrentPersonState() when you need to know how current the answer is:

val state = voidhash.getCurrentPersonState()
val hasPremium = state.value?.hasActivePerk("premium") == true

if (state.value == null && state.isExpired) {
    // Unknown: nothing is cached and Voidhash couldn't be reached. Don't lock by default.
}
FieldMeaning
valueThe person, or null.
isStalePast the 5-minute refresh window; a refresh is under way.
isExpiredPast the 2-day lifetime, or nothing cached and no answer. Still served.

A null person that isn't expired is a confirmed answer: Voidhash has no person for this identity yet, such as an anonymous visitor who hasn't bought anything.

Read the person

VoidhashPerson holds the person's identity and entitlements:

PropertyMeaning
distinctIdThe current distinct ID.
personIdVoidhash's ID for the person.
email, nameSet through identify or person attributes.
entitlementGrantsEvery grant, active or expired.
subscriptionscurrent, the subscription that matters most or null; all, every subscription that hasn't ended; and history. See Statuses.
purchaseshistory, every purchase the person owns or shares.
rawThe full JSON snapshot.

Each EntitlementGrant has these fields:

FieldMeaning
perkSlugThe perk's slug in Studio. Compare this one.
perkIdThe perk's internal ID.
statusactive or expired. isActive is true for active.
sourceWhat granted it: subscription, purchase or manual, a perk granted by hand.
sourceIdThe subscription, purchase or grant that granted it.
expiresAtWhen access ends, as an ISO 8601 string, or null for access that doesn't expire.

Use subscriptions for account screens, such as the current plan and its renewal date. Each subscription has its productSlug, store, status (ACTIVE, TRIALING, IN_GRACE_PERIOD, IN_BILLING_RETRY, ON_HOLD, PAUSED, EXPIRED, REVOKED), periodType (TRIAL, INTRO, REGULAR), expiresAt, willRenew, canceledAt, a coming change of product (renewsToProductSlug) or price (pendingPrice), gracePeriodExpiresAt, resumesAt for a paused subscription, and refundedAt. Every status, store and environment has an UNKNOWN value for one a newer Voidhash sends. Grant access from perks, never from these lists.

To keep a screen current, collect voidhash.person, a flow of the current person updated after every purchase, restore, identify and refresh.

Environments

The publishable key the client uses decides which purchases unlock perks. With the production key (vh_pk_…), production purchases count, plus store sandbox purchases such as Google Play test purchases while they unlock production apps. With the test key (vh_pk_test_…), store sandbox, simulated and test mode purchases count, never production ones. Use the test key in debug builds and the production key in release builds.

Next steps

Something wrong or missing on this page? Tell us by email or on Discord.