Anh Tran dev notes

Production bugs from mobile and backend work, written up with the fix and how it was checked.

Note 08 / RevenueCat / Subscriptions / Backend

RevenueCat in an app with accounts: restore behavior, guests and the Pro subscription two users shared

Why the default RevenueCat restore behavior lets two accounts hold the same subscription, which setting fixes it for apps with sign-in, why guests must never be identified, and how a webhook that skips TRANSFER events leaves the server wrong.

By
Trần Thế Anh, Software Engineer
Published
Work done
September and October 2026, apps with user accounts (Flutter and NestJS)
Stack
RevenueCat, App Store, Google Play Billing, NestJS webhook
Reading
7 min, 1,372 words

A store subscription belongs to a store account: an Apple ID or a Google account. An app with its own sign-in has a second identity on top of that. Mixing the two goes wrong in a specific way: a person holding one paid Apple ID can unlock Pro on any number of app accounts. This note is about the settings and code that stopped that in apps with accounts, and the checks that made it stick.

What the stores allow

Three facts frame everything:

  • An Apple ID holds one subscription per subscription group.
  • Apple offers no way to move a subscription to another person. The backend ties the original transaction to an app account (through appAccountToken), and Google does the same with obfuscatedAccountId.
  • So “one Apple ID buys for several app accounts” cannot be done through in-app purchase. The only way is to reassign, and a reassignment that happens automatically is the hole.

The setting

RevenueCat has a project-level option, “Handling multiple app user IDs”, which decides what happens when a receipt that belongs to user A is restored while user B is logged in.

  • Transfer to the new App User ID (default) moves the subscription to B.
  • Keep with original App User ID leaves it with A and fails the restore for B.

For an app with no accounts, where the app user id is a device id, Transfer is right: the person who restores is the owner. For an app with accounts, Transfer is the hole. Anyone with a paid Apple ID can sign in to a second account, press Restore, and the subscription jumps. Do it again and it jumps back. That was the case in September 2026: two accounts showed Pro from one purchase.

Apps with real sign-in, where sign-in comes before purchase, use Keep with original App User ID. The error that SDKs raise then is receiptAlreadyInUse or productAlreadyPurchased. Change the dashboard first, then change the code, because the code expects the new failure.

Guests cannot buy

If a guest session can purchase, the subscription attaches to a guest id nobody can sign back in to. So every path to a purchase checks for a real account first: the main paywall, a sale pop-up, a direct-sell sheet, a flash sale. A source-scan test enforces it: any file that calls the purchase function without going through the gate fails the test. Without such a test, a purchase button added later can skip the gate unnoticed.

After sign-in the user returns to the paywall. The app does not buy on their behalf.

Never logIn with a guest id

This one was found on Android. A guest session was identified with RevenueCat under a temporary id. The Android SDK sends every receipt of the Play account when the app opens. A real account bought a plan on device A. Device B, a guest on the same Google Play account, sent its receipts first and the plan was pinned to the guest id. It reproduced on a real device.

The rules that came out:

  1. A guest session stays on RevenueCat’s anonymous id. Do not logIn a guest uid, an anonymous uid or a temporary device id. If the session was identified and becomes a guest, logOut.
  2. Before any purchase or restore, read the user id back from the SDK and compare it with the expected one. A logIn error blocks the purchase. Swallowing it is a bug of its own, because the purchase then goes to whatever id the SDK happened to hold.
  3. Search other apps for the pattern: grep -rn "Purchases.logIn\|logIn(" lib src. Every hit should have a real account behind it.

Tell the user who owns the plan

With Keep, a restore by account B returns an error. A generic “purchase failed, try again” sends people into a loop. The app maps both error codes to one outcome, ownedByAnotherAccount, for both buying and restoring, and the toast names the account that holds the plan with the address masked (ab***@gmail.com). The app sends its own transaction id to a backend function; the function looks it up and returns the provider and the masked address, never the full address. If the lookup times out, a generic message shows, so the toast always appears.

The same applies to an empty restore. If Restore returns nothing, the lookup may still find an owner.

The server: do not reject TRANSFER

Even with Keep, a project can end up with TRANSFER events: someone changes the dashboard setting back, or an admin moves a plan by hand. The webhook handler has two obligations:

  • Branch on TRANSFER before resolving the user from app_user_id. A transfer event has no app_user_id; it has transferred_from and transferred_to. A handler that resolves the user first throws away the event, and the branch for transfers never runs. That is how an app in this set had a transfer handler that was dead code.
  • After the branch, read the state back from RevenueCat for every id in from and to and write what RevenueCat says. Never reject the event. RevenueCat has already moved the plan; if the backend refuses, nobody has Pro. Log an error loudly if an unexpected transfer arrives, because it means the restore setting changed.

Three points of reconciliation

Webhooks can be missed, since RevenueCat retries for a limited time and then drops them. So the server compares itself with RevenueCat in three places:

  1. On each webhook.
  2. When the app opens, through an entitlements endpoint, throttled to once per five minutes per user with a 1.5 second timeout.
  3. In an hourly job.

If RevenueCat answers 200 and the plan is gone from its answer, the matching local row expires. If the call errors, the user is not treated as Free: the state stays as it was. A grant someone made by hand is never touched. And the job reports a number (changed: 0 once things match), not just “ok”.

Deleting an account

Deleting the RevenueCat customer when a user deletes their account loses revenue history and strands a plan the store account still pays for. The rule is to keep the customer and remove only the email attribute. When the same person comes back with a new account and presses Restore, the server looks up the owner. If the old owner has been deleted and the caller is signed in for real, it uses RevenueCat’s v2 actions/transfer to move the plan to the new id, once. The attempt is recorded before the call, and a unique constraint on the old id means two simultaneous callers cannot both win. A living owner is never overridden.

Two small bans: no Family Sharing, and no in-app “transfer my plan” button. Moving a plan between two live accounts is a support task done in the dashboard, case by case, with a record.

Android suspended purchases

From Play Billing 8.1 a purchase can be suspended (for example, a failed renewal charge). isSuspended() has to be checked before granting Pro, and the user should be sent to the manage-subscription screen.

Tests that stayed green for the wrong reason

The transfer tests passed, and it still did not work. The fake RevenueCat used in the tests knew only one id, so the case “read back both from and to” never exercised the second one. A mutation check that removed that branch left three tests green. The fix was a fake that knows every id and a rule to run a mutation check on a billing test before trusting it.

What was not re-run

This is a summary of the project’s rules and the lessons they came from. I did not call RevenueCat, test a purchase, or re-run the account-deletion script while writing, and the sandbox and production behaviours differ in small ways (the sandbox has its own restore setting). Before trusting any of the points above, repeat the seven-step acceptance on real devices: a guest cannot reach the store, account A buys and gets Pro, account B on the same device is told who owns the plan and stays Free, A signs back in with Pro, and the backend log shows no TRANSFER.