🔐revenuecat-identify-user
- プラグイン
- revenuecat
- ソース
- GitHub で見る ↗
説明
RevenueCatのIDをアプリの認証システムと連携します。 次のような場合に使用: ユーザーがRevenueCatへのログイン、RevenueCatとのユーザー同期、ログイン時のRevenueCatユーザーの切り替え、RevenueCatからのログアウト、匿名ユーザーから識別済みユーザーへの移行、appUserIDの設定、またはiOS・Android・Kotlin Multiplatform・Flutter・React Nativeにおけるアカウント切り替えの処理を求めている場合。
原文を表示
Tie RevenueCat identity to your app's auth system. Use when the user asks to log in to RevenueCat, sync a user with RevenueCat, switch RevenueCat user on login, log out of RevenueCat, move a user from anonymous to identified, set appUserID, or handle account switching on iOS, Android, Kotlin Multiplatform, Flutter, or React Native.
ユースケース
- ✓RevenueCatへのログイン
- ✓ユーザー同期処理
- ✓ログイン時のユーザー切り替え
- ✓RevenueCatからのログアウト
- ✓匿名から識別済みユーザーへの移行
- ✓appUserIDを設定するとき
本文(日本語訳)
revenuecat-identify-user: RevenueCatを認証システムと連携する
次のような場合に使用:
ユーザーがRevenueCat SDKのlogIn / logOutを呼び出して、アプリのユーザーとRevenueCatのサブスクライバーを紐付けたいとき。
このスキルは、SDKの初期セットアップ(integrate-revenuecatを参照)、購入処理(revenuecat-purchase-flow)、エンタイトルメントによるアクセス制御(revenuecat-entitlements-gate)はカバーしません。
1. プラットフォームの検出
作業ディレクトリを調べ、以下の順番で最初に一致したものを採用してください:
- React Native:
package.jsonにreact-native-purchasesのエントリがある、またはreact-nativeが依存関係にある →platforms/react-native.mdを参照。expoも依存関係にある場合は、Expoプロジェクトとして記録する。 - Flutter: プロジェクトルートに
pubspec.yamlが存在する →platforms/flutter.mdを参照。 - Kotlin Multiplatform:
build.gradle.ktsにkotlin { … }のマルチプラットフォームソースセットブロックが含まれている、またはcom.revenuecat.purchases:purchases-kmp*に依存している →platforms/kmp.mdを参照。 - Android(ネイティブ):
build.gradle(.kts)がcom.android.applicationを適用している(かつKMPではない)→platforms/android.mdを参照。 - iOS(ネイティブ): プロジェクトルートに
Package.swift、*.xcodeproj、*.xcworkspace、またはPodfileが存在する →platforms/ios.mdを参照。
複数が一致する場合(例: Flutterプロジェクト内にios/フォルダがある場合)は、ビルドを管理している最も外側のプロジェクトを選択してください。
それでも判断が難しい場合は、どのプラットフォームを設定するかユーザーに確認してください。
2. 共通の概念(全プラットフォーム共通)
-
デフォルトは匿名ユーザー。
logInが呼ばれる前、RevenueCatは$RCAnonymousID:というプレフィックスの付いた安定した匿名IDをユーザーに割り当てます。 匿名状態で行われた購入は、初めてlogInが呼ばれた際に実際のappUserIDにエイリアスされるため、サインイン前に購入しても「購入が失われる」リスクはありません。 -
appUserIDにメールアドレス・電話番号・連番のDBのIDは絶対に使用しない。 バックエンドのユーザーUUIDや、ユーザーIDのハッシュ値など、安定した不透明な値を使用してください。 RevenueCatはIDを不透明な文字列として扱うため、後から変更することは困難です。
-
logInは認証システムがセッションを確認した後に呼び出す。 投機的にlogInを呼び出さないでください。 典型的なトリガーは、サインイン済みユーザーに対して認証状態リスナーが発火したときです。logInはユーザーの現在のCustomerInfoと、そのユーザーが新規のRevenueCatカスタマーかどうかを示すcreated: Booleanの両方を返します。 -
logOutは識別済みユーザーに対してのみ有効。 SDKが匿名IDの状態でlogOutを呼び出すと、すべてのSDKでエラーがスローされます(PurchasesErrorCode.LogOutWithAnonymousUserErrorまたはiOS相当のエラー)。 自前の「サインイン済み」フラグでガードするようにしてください。 -
リストアはログインではない。
restorePurchases()は現在のレシートをストアに問い合わせ、現在のRevenueCatユーザーに紐付けます。 ユーザーのIDを切り替えるものではありません。 新しいデバイスでユーザーがサインインする場合は、まずlogIn(appUserID)を呼び出し、現在のストアアカウントからレシートを取得する必要がある場合にのみrestorePurchases()を呼び出してください。 -
アカウントの切り替えは
logOutしてからlogIn。 アプリがサインアウトして別のアカウントでサインインし直せる仕様の場合、まずlogOut()を呼び出して完了を待ってからlogIn(newId)を呼び出してください。 2回目のlogInで直接切り替えようとすると、2つのIDがエイリアスされてしまうため避けてください。 -
事前に
configureを実行しておく。logIn/logOutの前にPurchases.configure(…)が実行済みである必要があります。 実行されていない場合、SDKはエラーをスローします。
3. 実装
検出結果に対応するプラットフォームファイルを参照してください:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
各プラットフォームファイルには、典型的な認証状態オブザーバーに組み込んだlogInとlogOutの呼び出し例が記載されています。
4. 動作確認
以下がすべて確認できるまで、ID同期が正常に機能していると判断しないでください:
- RevenueCatダッシュボードのテストユーザーのCustomerページに、
$RCAnonymousID:プレフィックスではなく、バックエンドと同じappUserIDが表示されている。 - サインアウトするとIDがリセットされ新しい匿名ユーザーに戻り、別のアカウントでサインインするとそのアカウントの購入履歴に切り替わる(新規アカウントの場合は購入履歴なし)。
- 匿名状態で行った購入が、その後
logInを呼び出した後もサインイン済みユーザーに紐付いたままである(エイリアスされており、失われていない)。 - すでに匿名状態で
logOutを呼び出した場合に、クラッシュやサイレントな成功として扱われず、適切にハンドリングされている。
原文(English)を表示
revenuecat-identify-user: connect RevenueCat to your auth system
Use this skill when the user wants to call logIn / logOut on the RevenueCat SDK so that their app users line up with RevenueCat subscribers. This skill does not cover initial SDK setup (see integrate-revenuecat), purchases (revenuecat-purchase-flow), or gating (revenuecat-entitlements-gate).
1. Detect the platform
Inspect the working directory and pick the first match, from top to bottom:
- React Native:
package.jsonhas areact-native-purchasesentry, orreact-nativeas a dependency → readplatforms/react-native.md. Ifexpois also a dependency, note it as an Expo project. - Flutter:
pubspec.yamlexists at the project root → readplatforms/flutter.md. - Kotlin Multiplatform:
build.gradle.ktscontains akotlin { … }multiplatform source sets block, or depends oncom.revenuecat.purchases:purchases-kmp*→ readplatforms/kmp.md. - Android (native):
build.gradle(.kts)appliescom.android.application(and is not KMP) → readplatforms/android.md. - iOS (native):
Package.swift,*.xcodeproj,*.xcworkspace, orPodfileat the project root → readplatforms/ios.md.
If several match (e.g. an ios/ folder inside a Flutter project), pick the outermost project, the one that owns the build. If still ambiguous, ask the user which platform they want to configure.
2. Shared concepts (all platforms)
- Anonymous by default. Before
logInis called, RevenueCat assigns a stable anonymous ID prefixed$RCAnonymousID:. Purchases made while anonymous are aliased onto the realappUserIDthe first timelogInis called with it, so there is no "lost purchase" risk from letting users buy before signing in. - Never use email, phone number, or a sequential database id as the appUserID. Use a stable opaque value such as your backend's user UUID, or a hash of the user id. RevenueCat treats the ID as an opaque string and it is difficult to change later.
- Call
logInafter your auth system confirms the session. Do not calllogInspeculatively. The typical trigger is your auth state listener firing with a signed in user.logInreturns both the user's currentCustomerInfoand acreated: Booleanthat tells you whether this is a brand new RevenueCat customer. logOutonly works on identified users. CallinglogOutwhile the SDK is on an anonymous ID throws an error in every SDK (PurchasesErrorCode.LogOutWithAnonymousUserErroror the iOS equivalent). Gate it behind your own "is signed in" flag.- Restore is not login.
restorePurchases()asks the store for the current receipt and attaches it to the current RevenueCat user. It does not switch identities. If the user signs in on a new device, calllogIn(appUserID)first, thenrestorePurchases()only if they also expect to pull a receipt from the current store account. - Account switching is
logOutthenlogIn. If your app lets a user sign out and sign back in as someone else, calllogOut()first, wait for it, thenlogIn(newId). Do not try to swap directly with a secondlogIn, since that will alias the two IDs together. - Configure first.
Purchases.configure(…)must have run beforelogIn/logOut. If it has not, the SDK throws.
3. Implementation
Read the platform file that matches detection:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
Each platform file shows the logIn and logOut calls wired into a typical auth state observer.
4. Verify
Do not claim identity sync works until:
- In the RevenueCat dashboard, the Customer page for your test user shows the same appUserID your backend uses, not the
$RCAnonymousID:placeholder. - Signing out clears the ID back to a fresh anonymous user; signing in as a different account switches to that account's purchases (or shows none if it is a new account).
- A purchase made while anonymous, followed by
logIn, remains attached to the signed in user (aliased, not lost). - Calling
logOutwhile already anonymous is handled, not treated as a crash or a silent success.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。