Skip to main content
coreydaley.dev

A free tier with no server: Secret Store's 10-secret cap

Update, November 20, 2026: Secret Store 1.2 dropped the cap and the in-app purchase, so it’s completely free now. This post describes how the cap worked before that.

Secret Store has no server, so nothing upstream knows who paid. The app keeps API keys, recovery codes and other small secrets in iCloud Keychain, with no account and no network calls of its own. It’s free for 10 secrets, and a one-time in-app purchase, Secret Store Unlimited, removes the cap.

The only source of truth for that purchase is StoreKit 2’s verified transactions on the device, so the cap has to be enforced from those alone. That runs on a device the user controls, and nobody determined to patch the app will be stopped by it. The goal isn’t an unbreakable cap. It’s that an honest user is never punished by it. Enforcing the cap is the mechanical part. Making it feel fair took two passes.

Four states, and one of them never gates

The entitlement is an enum with four cases:

public enum EntitlementStatus: Sendable, Equatable {
    case bootstrapping   // StoreKit hasn't answered yet
    case free            // capped at Entitlement.freeSecretCap (10)
    case pending         // Ask-to-Buy, waiting on a parent
    case unlimited       // purchased or family-shared
}

pending is easy: a purchase waiting for a parent’s approval hasn’t been paid for, so it’s treated exactly like free.

bootstrapping matters more. At launch, the app starts listening for transaction updates and then reads Transaction.currentEntitlements, which takes a moment. If the app gated during that moment, someone who had paid could see “free limit reached” on a cold launch. So bootstrapping never gates. The same goes for the secret count: until the first keychain load finishes, the app doesn’t know how many secrets exist, so it doesn’t gate on a number it hasn’t read yet.

All of that fits in one pure function, shown here slightly condensed:

public func canCreate(
    currentCount: Int,
    status: EntitlementStatus,
    hasCompletedInitialLoad: Bool
) -> Bool {
    switch status {
    case .bootstrapping, .unlimited:
        return true
    case .free, .pending:
        guard hasCompletedInitialLoad else { return true }
        return currentCount < Entitlement.freeSecretCap
    }
}

The view-model’s create() calls it before any keychain write. It reads the status and the count with no await in between, so neither can change in the middle of the check. Views never repeat the number 10 or the threshold logic. If the cap ever changes, it changes in one constant.

Show the paywall before the form

The first pass got the order wrong. A free user at the cap could open New Secret, type a name, paste in the secret, press Add, and only then see the error. The view caught it, closed the sheet, and opened the paywall. The secret they had just pasted was thrown away.

Now the entry points ask first. requestAdd() runs the same canCreate check that create() uses, and opens either the form or the paywall:

public func requestAdd() {
    if canCreate(currentCount: metas.count,
                 status: entitlementProvider.status,
                 hasCompletedInitialLoad: hasCompletedInitialLoad) {
        showingAdd = true
    } else {
        showingPaywall = true
    }
}

Importing secrets from files is an Unlimited feature, so requestImport() sends a free user to the paywall before the file picker opens, not after they’ve chosen files. create() still checks the cap itself, so the early check is about not wasting the user’s time.

The sidebar also shows how close you are. A small gauge reads “N/10” and changes color as it fills: the accent color up to 5, orange from 6 to 9, and red at 10. Nobody should reach the paywall by surprise.

One macOS gotcha: two sheets, one window

The paywall started as a .sheet on the main window. StoreKit’s own purchase sheet needs to attach to a window too, and macOS allows one sheet per window. With both on the same window, the purchase silently came back as .userCancelled, with no error to point at the cause.

The paywall now opens in its own Window scene, and StoreKit has the main window to itself. If your Mac app’s purchases report a cancel nobody made, check what else is presented on that window.

The grace rule

A free user can’t get past 10 secrets. But there is a way to end up over the cap: buy Unlimited, add 30 secrets, then lose the entitlement through a refund or a revocation.

The rule for that state is simple: secrets are never hidden or deleted when the entitlement drops. Locking someone out of their own recovery codes because a payment record changed is not an option.

The first grace rule only blocked creating new secrets. Over the cap, you could still view, reveal, copy, edit and delete everything. That’s non-destructive, but it leaves an obvious hole: buy, add as many secrets as you like, request a refund, and keep a fully working, unlimited vault.

The second pass freezes edits too:

ActionOver the cap, unentitled
View, reveal, copyAllowed
DeleteAllowed, and it frees a slot
Edit name, notes or valueBlocked (editLockedOverCap)
Create or importBlocked (capReached)

The vault becomes a read-only snapshot. Everything is still there, and still usable for what you’d need in a hurry: reading and copying a value. That does mean someone who refunds keeps read access to secrets beyond the free 10. That’s deliberate. I’d rather give that away than hold anyone’s recovery codes hostage. What the vault no longer does is work as a live, growing store nobody paid for.

The lock is a computed property on the @Observable view-model:

public var isEditingLockedOverCap: Bool {
    let s = entitlementProvider.status
    return (s == .free || s == .pending) && isOverFreeCap
}

It’s only true for a settled free or pending status, never while bootstrapping. And it recovers by itself. Delete back down to 10, or buy again, and the property goes false and the Edit button comes back without a relaunch.

That recovery matters for one case that doesn’t involve a refund. On a new device, iCloud Keychain can deliver your secrets before StoreKit has synced your purchase, and for that window StoreKit reports no entitlement. A paying user with more than 10 secrets can briefly see editing paused. Nothing is hidden, and when the purchase arrives through Transaction.updates the status flips to unlimited and editing comes back on its own.

The disabled Edit button isn’t the enforcement. updateMeta and updateValue both start with guard !isEditingLockedOverCap else { throw SecretError.editLockedOverCap }, so a code path that forgets to check the button state still can’t write. The button’s tooltip explains why editing is paused, and an over-cap user with nothing selected sees the same explanation in the empty detail pane.

Honest messaging

I wrote the no-hiding rule into the project’s instructions so it doesn’t erode later. Gates block new writes and edits. Existing data is always viewable and deletable.

The messaging follows the same rule. The over-cap error says what’s happening and offers both ways out, including the free one:

Editing is paused while you’re over the 10-secret free limit. Delete secrets to get back under the limit, or unlock Secret Store Unlimited.

“Delete a few, or unlock” is honest. “Upgrade to keep your data” would be a lie.

This matters for App Review as well as for users. A reviewer who somehow lands in the over-cap state shouldn’t see what looks like data being held for ransom. The review notes now have a short section that explains it: it’s reachable only after a refund of an over-cap purchase, nothing is hidden or deleted, only editing and creating pause, and deleting back to 10 or buying again ends it immediately.

Tested without StoreKit

The gate and the grace rule live in the shared core package and take any EntitlementProvider, so the tests use a fake provider and never touch StoreKit. A few of the test names describe the policy better than prose:

  • eleventhCreateThrowsCapReached and capReachedWritesNothing
  • pendingDoesNotLiftTheCap
  • bootstrappingDoesNotGate
  • overCapOnStatusFlipDoesNotHideSecrets
  • overCapEditIsBlocked and overCapRevealSucceeds
  • editReenablesAfterDeletingUnderCap
  • unlimitedOverCapEditSucceeds

The StoreKit side, the provider that reads verified transactions, has its own SKTestSession tests. The cap’s rules don’t depend on them.

What to take away

  • Give “we don’t know yet” its own state, and never gate on it.
  • Put the threshold in one function and call it from the entry point as well as the write, so users hit the paywall before they do any work.
  • Decide what happens to existing data when an entitlement disappears, and make the answer “nothing is lost.”
  • Enforce restrictions in the model. A disabled button is an explanation, not a lock.

Would you have frozen edits after a refund, or left the over-cap vault fully working and accepted the hole?

Related posts