---
title: "How to link in-app purchases to your user accounts"
description: "Link App Store and Google Play purchases to your own user IDs with logIn, Apple's appAccountToken and Google's obfuscatedAccountId, and handle purchases made outside the app."
url: https://revenuedot.app/blog/link-in-app-purchases-to-user-accounts
---

# How to link in-app purchases to your user accounts

To link an in-app purchase to a user in your own database, give every signed-in user one stable, random ID, and attach that ID to each purchase in three places: your purchase SDK's `logIn` call, Apple's `appAccountToken` on iOS, and Google's `obfuscatedAccountId` on Android. Then your server can match every receipt and every store notification to the right account, even for purchases the customer makes outside your app.

This post is for Flutter, React Native, Expo and native apps that have their own sign-in (often Supabase, Firebase Auth or a custom backend) and sell on the App Store and Google Play. It explains which ID to use, the code for each store, the cases that break the link, and how to repair a purchase that landed on the wrong account. Every fact about Apple, Google and RevenueCat links its source and was checked on November 30, 2026.

![Three layers that carry one user ID: the purchase SDK's logIn, Apple's appAccountToken and Google's obfuscatedAccountId, all pointing at one row in your users table](https://revenuedot.app/blog/assets/link-in-app-purchases-to-user-accounts/cover.svg)

## The short answer

- **Pick one ID per user and never change it.** A random UUID from your own database is the best choice. Do not use an email address or anything a stranger could guess.
- **Call `logIn` with that ID** right after sign-in and before you show a paywall. The purchase SDK then sends every receipt under that ID.
- **On iOS, pass the same UUID as `appAccountToken`.** Apple returns it in the transaction, in the renewal info and in every server notification ([Apple](https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken)).
- **On Android, pass a hash of the ID as `obfuscatedAccountId`.** Google limits it to 64 characters and blocks purchases that put personal data in it ([Android Developers](https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder#setObfuscatedAccountId(java.lang.String))).
- **Purchases outside the app need a server fix.** An offer code redeemed in the App Store has no token, so Apple's Set App Account Token endpoint adds one later ([Apple](https://developer.apple.com/documentation/appstoreserverapi/set-app-account-token)).
- **Decide what a restore does** when a second account claims the same purchase, before your first support ticket arrives.

## Why the link matters

A store purchase belongs to an Apple Account or a Google account, not to your user. Apple and Google do not know that `ana@example.com` in your app is the same person who paid. If your app runs only on one phone and has no sign-in, that is fine, because the purchase and the device stay together.

The problem starts when you add accounts. A subscriber signs in on an iPad and expects access. Your web app needs to know who paid. Your server gates an AI feature by plan. A customer gets a new phone and signs in with Google instead of Apple. Each of these needs a record that says "this purchase belongs to user 42", and that record must survive renewals, refunds and plan changes.

There are two ways to build the record. The app can tell your server "user 42 just bought this" after each purchase, which works until the app crashes in the gap. Or the store can carry your user ID inside the purchase itself, so every notification already names the user. The robust answer is to do both.

## Step 1: Choose one stable user ID

The ID you choose here is used for years, so choose carefully.

| Option | Good for linking? | Why |
|---|---|---|
| A random UUID you create at sign-up | Yes, the best choice | Stable, unguessable, and valid as Apple's `appAccountToken` |
| Your database's numeric primary key | Works, with care | Stable, but guessable, and not valid as an `appAccountToken` |
| The auth provider's user ID | Usually fine | Stable, but check its format before you use it as an `appAccountToken` |
| Email address | No | People change emails, and it is personal data in every log and webhook |
| Device or advertising ID | No | It changes with reinstalls and privacy settings |

RevenueCat's guide on identifying customers gives the same advice. It says every app user ID "must be unique per user", that IDs "should not be guessable", and that "a non-guessable pseudo-random ID, like a UUID (RFC 4122 version 4), is recommended". It also says they "don't recommend using email addresses as App User IDs" and that IDs should not be longer than 100 characters ([RevenueCat](https://www.revenuecat.com/docs/customers/identifying-customers)).

The UUID format matters for one more reason. Apple's `appAccountToken` must be a UUID ([Apple](https://developer.apple.com/documentation/storekit/product/purchaseoption/appaccounttoken(_:))). If your user ID already is one, you can use the same value everywhere and never keep a mapping table. If your auth provider uses another format, add a `purchase_uuid` column to your users table, fill it once at sign-up, and use that column for purchases.

## Step 2: Call logIn after sign-in

A purchase SDK such as RevenueCat's starts every install with an anonymous ID. When the user signs in, call `logIn` with your ID. RevenueCat's guide says the identity "will be created automatically" if it does not exist yet, and that an anonymous user who logs in to a new ID has their purchases merged into it ([RevenueCat](https://www.revenuecat.com/docs/customers/identifying-customers)).

Here is the order that avoids lost purchases in a Flutter app with Supabase Auth:

```dart
// After Supabase sign-in succeeds, and before any paywall is shown.
final user = Supabase.instance.client.auth.currentUser!;
final result = await Purchases.logIn(user.id);   // your stable ID
// result.customerInfo now holds purchases made before sign-in, merged in.

// On sign-out, start a new anonymous customer so the next user
// on this device does not inherit the subscription.
await Purchases.logOut();
```

The same calls exist in React Native and Expo (`Purchases.logIn(userId)`), Swift (`Purchases.shared.logIn(userId)`) and Kotlin. Three rules keep this safe:

1. **Call `logIn` before the paywall.** A purchase made while the app is still anonymous lands on the anonymous ID. It usually merges later, but not in every case.
2. **Use the same ID on every platform.** The iOS app, the Android app and your web checkout must all send the same value for the same person.
3. **Call `logOut` on sign-out only if your app allows several accounts on one device.** If it does not, RevenueCat's guide suggests you simply do not log the SDK out.

## Step 3: Put the ID inside the Apple transaction

`logIn` links purchases that go through the app. Apple's `appAccountToken` goes further, because the App Store stores it in the purchase itself. Apple's reference says the App Store "returns the same UUID" in the transaction information and in the subscription renewal information after the purchase ([Apple](https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken)). That means every App Store Server Notification for that subscription, including renewals months later, already names your user.

With StoreKit 2 directly:

```swift
// purchaseUUID is the UUID you stored for this user at sign-up.
let result = try await product.purchase(options: [.appAccountToken(purchaseUUID)])
if case .success(let verification) = result,
   case .verified(let transaction) = verification {
    // transaction.appAccountToken == purchaseUUID
    await grantAccess(for: transaction)
    await transaction.finish()
}
```

With a purchase SDK, you usually do not call this yourself. A RevenueCat staff member explains that the `appAccountToken` field "will be empty unless you generate and use a UUID as the App User ID", and recommends "generating a UUID for each user and using that as the App User ID" ([RevenueCat Community](https://community.revenuecat.com/general-questions-7/what-functionality-do-we-lose-if-we-don-t-use-a-uuid-for-app-user-id-6441)). So the UUID choice in step 1 is what makes this work. An anonymous ID such as `$RCAnonymousID:...` is not a UUID, so purchases made before sign-in carry no token.

### Purchases made outside your app

Some purchases never pass through your app's purchase call. The clearest case is an offer code redeemed in the App Store app. Apple's documentation says that in that case "the original transaction doesn't include an app account token", and offers the Set App Account Token endpoint to add one ([Apple](https://developer.apple.com/documentation/appstoreserverapi/set-app-account-token)).

The endpoint is `PUT /inApps/v1/transactions/{originalTransactionId}/appAccountToken`. Apple's page lists the rules that matter:

- It works for every product type, including consumables and auto-renewable subscriptions.
- It replaces any token that the transaction already has.
- For a subscription, it applies to the current renewal and every later one, and it keeps applying after an upgrade, downgrade or crossgrade. It does not change past transactions.
- It does not work for products shared through Family Sharing.

So the repair flow is short. When the app first sees a transaction without a token (for example, in StoreKit's `Transaction.updates` listener after the customer opens the app), send its original transaction ID and the signed-in user to your server. The server checks the transaction with the App Store Server API and then sets the token, so future notifications name the user.

## Step 4: Put the ID inside the Google Play purchase

Google Play has a similar field with a different purpose. `setObfuscatedAccountId` takes "an optional obfuscated string that is uniquely associated with the purchaser's user account in your app". Google uses it to spot fraud, such as "many devices making purchases on the same account within a brief timeframe", and you can read it back from the `Purchase` object ([Android Developers](https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder#setObfuscatedAccountId(java.lang.String))).

Two rules from the same page are strict:

- **No personal data.** Google says that storing personal data such as a cleartext email "results in purchases being blocked", and recommends encryption or a one-way hash.
- **64 characters at most.** A SHA-256 hash in hex is exactly 64 characters, and a UUID is 36.

```kotlin
// Kotlin, Play Billing Library. accountHash = sha256Hex(purchaseUuid)
val params = BillingFlowParams.newBuilder()
    .setProductDetailsParamsList(listOf(productParams))
    .setObfuscatedAccountId(accountHash)
    .build()
billingClient.launchBillingFlow(activity, params)
```

Your server then reads the same value from the Google Play Developer API (`externalAccountIdentifiers.obfuscatedExternalAccountId` on a subscription from `purchases.subscriptionsv2.get`) and matches it to the user. Google's security guide asks you to do exactly this check before you grant access: if you set the field, "check that the purchase mapping matches the expected user account in your system" ([Android Developers](https://developer.android.com/google/play/billing/security#verify)).

A resubscribe from the Play Store does not pass through your app either. It arrives with a new purchase token and, often, no account ID. For those, link by `linkedPurchaseToken`, which points at the earlier purchase that you already linked.

## When two accounts claim one purchase

One Apple Account or Google account can be signed in to two of your app's accounts. A customer buys on account A, signs out, signs in as B, and taps Restore. The store returns the same purchase, and your backend must decide who owns it. Common choices:

| Rule | What happens | Good for |
|---|---|---|
| Transfer | The purchase moves to B; A loses access | Most consumer apps |
| Transfer only if A has no active subscription | B gets an error while A is subscribed | Apps where sharing accounts is a problem |
| Keep with the first owner | B always gets an error | Apps that sell per seat |
| Share | Both accounts keep access | Family or couple apps |

Write the rule down, put it in your support replies, and log every transfer. Our post on [restore purchases](https://revenuedot.app/blog/restore-purchases-ios-android.md) shows what App Review expects from the Restore button.

## Do it with RevenueDot

RevenueDot is an open-source backend for in-app purchases and subscriptions on the App Store, Google Play and the web. Here is how it handles each part of this post:

- **logIn and merges.** `logIn` attaches your ID to the customer. An anonymous customer that logs in to a new ID keeps its purchases, and an anonymous customer that logs in to an existing ID is merged into it unless that ID already has an anonymous ID of its own. The full table is in [customers and app user IDs](https://revenuedot.app/docs/concepts/customers-and-app-user-ids.md).
- **App Store notifications use the token.** When Apple sends a notification about a purchase RevenueDot has not seen, such as an offer code redeemed in the App Store, and its `appAccountToken` equals an existing customer's app user ID, RevenueDot records the purchase on that customer. With **Track new purchases from server-to-server notifications** turned on, it also creates the customer if none exists. The code is in [stores/apple/notifications.ts](https://github.com/revenuedot/revenuedot/blob/main/apps/server/src/stores/apple/notifications.ts) and [services/purchases.ts](https://github.com/revenuedot/revenuedot/blob/main/apps/server/src/services/purchases.ts).
- **Promotional offers carry the same token.** When the app user ID is a UUID, RevenueDot signs iOS promotional offers with it as the `appAccountToken` ([services/promo-offers.ts](https://github.com/revenuedot/revenuedot/blob/main/apps/server/src/services/promo-offers.ts)).
- **Google Play links by purchase token.** RevenueDot links a Google Play purchase to the customer whose app posted its token, and links upgrades, downgrades and resubscribes through `linkedPurchaseToken`. It does not read `obfuscatedExternalAccountId` today, so keep your own check if you rely on it.
- **You pick the restore rule.** The four rules in the table above are the project's transfer behavior, set in **Project settings** or with the API. A move fires a `TRANSFER` [webhook](https://revenuedot.app/docs/guides/webhooks.md) with both customers' IDs, so your own database follows.

To be clear about where this stands: a real App Store sandbox purchase has run end to end against RevenueDot. Google Play handling is tested against a copy of Google's API, and no real Google Play purchase has yet run end to end.

New apps install the [RevenueDot SDK](https://revenuedot.app/docs/sdks.md). Its code says `import RevenueCat` because it is built from RevenueCat's MIT-licensed SDK, and it needs no RevenueCat account. Our post on [syncing subscription status to your backend](https://revenuedot.app/blog/sync-subscription-status-to-your-backend.md) shows the webhook receiver that keeps your users table current, and the [Flutter](https://revenuedot.app/blog/flutter-in-app-purchases-tutorial.md) and [React Native and Expo](https://revenuedot.app/blog/react-native-expo-subscriptions-tutorial.md) tutorials set up the app.

**Switching from RevenueCat? Keep your SDK and change one line.** An app that ships the RevenueCat SDK points its proxy URL at RevenueDot and keeps its app user IDs, `logIn` calls and customers. The [importer](https://revenuedot.app/blog/migrating-from-revenuecat-without-data-loss.md) brings every customer across under the same IDs. See the [comparison](https://revenuedot.app/compare/revenuedot-vs-revenuecat) and the [fee calculator](https://revenuedot.app/tools/revenuecat-fee-calculator).

[Start for free on RevenueDot Cloud](https://app.revenuedot.app/signup). Building and testing are free, no card needed. Add a card when you go live; Pro costs $0 until your apps make $10,000 a month. See [pricing](https://revenuedot.app/pricing).

## FAQ

### How do I connect a RevenueCat or RevenueDot customer to my Supabase user?

Call `Purchases.logIn` with the Supabase user's ID right after sign-in and before you show a paywall. Then read `app_user_id` in your webhook handler and update the row with that ID. Use the same ID in the iOS app, the Android app and any web checkout.

### What is appAccountToken in StoreKit 2?

It is a UUID you attach to a purchase with `Product.PurchaseOption.appAccountToken(_:)`. Apple stores it with the transaction and returns it in the transaction, the renewal info and server notifications, so your server knows which of your users bought ([Apple](https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken)).

### Why is appAccountToken empty on my transactions?

Either the purchase was made outside your app, for example with an offer code in the App Store, or the ID you passed was not a UUID. RevenueCat staff say the field stays empty unless the app user ID is a UUID ([RevenueCat Community](https://community.revenuecat.com/general-questions-7/what-functionality-do-we-lose-if-we-don-t-use-a-uuid-for-app-user-id-6441)). Set it later with Apple's Set App Account Token endpoint.

### Can I put the user's email in obfuscatedAccountId?

No. Google says that personal data such as a cleartext email in this field "results in purchases being blocked". Send a one-way hash of your user ID instead, at most 64 characters long ([Android Developers](https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder#setObfuscatedAccountId(java.lang.String))).

### Should I use the email address as the app user ID?

No. Emails change, they are personal data that ends up in every log and webhook, and RevenueCat's guide advises against them ([RevenueCat](https://www.revenuecat.com/docs/customers/identifying-customers)). Use a random UUID from your own database.

**About RevenueDot.** RevenueDot is an open-source (AGPL-3.0) backend for in-app purchases and subscriptions on the App Store, Google Play and the web. Start for free on [RevenueDot Cloud](https://app.revenuedot.app/signup): Pro costs $0 until your apps make $10,000 a month, then 0.5% of revenue above $10,000, never more than $999 a month. New apps install the [RevenueDot SDK](https://revenuedot.app/docs/sdks.md) and pass their key. Apps that ship the RevenueCat SDK point its proxy URL at RevenueDot and keep their code, offerings and customers. Read the [quickstart](https://revenuedot.app/docs/getting-started/quickstart.md) or the code on [GitHub](https://github.com/revenuedot/revenuedot).
