RevenueCat(アプリ内課金管理サービス)の認証をアプリの認証システムと連携させます。 次のような場合に使用: - ユーザーが 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 SDKのlogIn / logOutを呼び出し、アプリのユーザーとRevenueCatのサブスクライバーを紐付けたい場合。
このスキルは、SDKの初期セットアップ(integrate-revenuecatを参照)、購入処理(revenuecat-purchase-flow)、アクセス制御(revenuecat-entitlements-gate)はカバーしません。
作業ディレクトリを調べ、以下の順番で最初に一致したものを採用してください:
package.jsonにreact-native-purchasesのエントリがある、またはreact-nativeが依存関係に含まれている → platforms/react-native.mdを読む。expoも依存関係にある場合は、Expoプロジェクトとして記録する。pubspec.yamlが存在する → platforms/flutter.mdを読む。build.gradle.ktsにkotlin { … }のマルチプラットフォームソースセットブロックが含まれる、またはcom.revenuecat.purchases:purchases-kmp*に依存している → platforms/kmp.mdを読む。build.gradle(.kts)がcom.android.applicationを適用している(かつKMPではない)→ platforms/android.mdを読む。Package.swift、*.xcodeproj、*.xcworkspace、またはPodfileがある → platforms/ios.mdを読む。複数一致する場合(例: Flutterプロジェクト内にios/フォルダがある場合)は、ビルドを管理している最外側のプロジェクトを選択してください。
それでも判断できない場合は、ユーザーにどのプラットフォームを設定したいか確認してください。
デフォルトは匿名。
logInを呼び出す前は、RevenueCatが$RCAnonymousID:というプレフィックス付きの安定した匿名IDを割り当てます。
匿名状態で行われた購入は、最初にlogInが呼び出された際に実際のappUserIDにエイリアスされるため、サインイン前に購入しても「購入が失われる」リスクはありません。
メールアドレス・電話番号・連番のデータベースIDをappUserIDに使用しないこと。 バックエンドのユーザーUUIDや、ユーザーIDのハッシュ値など、安定した不透明な値を使用してください。 RevenueCatはIDを不透明な文字列として扱うため、後から変更することは困難です。
logInは認証システムがセッションを確認した後に呼び出すこと。
投機的にlogInを呼び出してはいけません。
典型的なトリガーは、サインイン済みユーザーに対して認証状態リスナーが発火したタイミングです。
logInは、ユーザーの現在のCustomerInfoと、そのユーザーが新規のRevenueCatカスタマーかどうかを示すcreated: Booleanの両方を返します。
logOutは識別済みユーザーに対してのみ機能する。
SDKが匿名IDの状態でlogOutを呼び出すと、すべてのSDKでエラーがスローされます(PurchasesErrorCode.LogOutWithAnonymousUserErrorまたはiOS相当のエラー)。
独自の「サインイン済み」フラグでガードしてください。
Restoreはログインではない。
restorePurchases()はストアに現在のレシートを問い合わせ、現在のRevenueCatユーザーにアタッチします。
IDの切り替えは行いません。
新しいデバイスでサインインする場合は、まずlogIn(appUserID)を呼び出し、現在のストアアカウントからレシートを取得する必要がある場合にのみrestorePurchases()を呼び出してください。
アカウントの切り替えはlogOutの後にlogIn。
アプリがサインアウトして別のユーザーとしてサインインし直すことを許可している場合は、まずlogOut()を呼び出して完了を待ち、その後logIn(newId)を呼び出してください。
2回目のlogInで直接切り替えようとすると、2つのIDがエイリアスされてしまうため避けてください。
事前にConfigureを実行すること。
logIn / logOutの前にPurchases.configure(…)が実行済みでなければなりません。
未実行の場合、SDKはエラーをスローします。
検出したプラットフォームに対応するファイルを読んでください:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md各プラットフォームファイルには、典型的な認証状態オブザーバーに組み込まれたlogInおよびlogOutの呼び出し例が記載されています。
以下がすべて確認できるまで、ID同期が機能していると主張しないこと:
$RCAnonymousID:のプレースホルダーではなく、バックエンドが使用している同一のappUserIDが表示されている。logInを呼び出すと、購入はサインイン済みユーザーにエイリアスされ、失われずに紐付いている。logOutを呼び出した場合に、クラッシュや無言の成功として扱われず、適切にハンドリングされている。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).
Inspect the working directory and pick the first match, from top to bottom:
package.json has a react-native-purchases entry, or react-native as a dependency → read platforms/react-native.md. If expo is also a dependency, note it as an Expo project.pubspec.yaml exists at the project root → read platforms/flutter.md.build.gradle.kts contains a kotlin { … } multiplatform source sets block, or depends on com.revenuecat.purchases:purchases-kmp* → read platforms/kmp.md.build.gradle(.kts) applies com.android.application (and is not KMP) → read platforms/android.md.Package.swift, *.xcodeproj, *.xcworkspace, or Podfile at the project root → read platforms/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.
logIn is called, RevenueCat assigns a stable anonymous ID prefixed $RCAnonymousID:. Purchases made while anonymous are aliased onto the real appUserID the first time logIn is called with it, so there is no "lost purchase" risk from letting users buy before signing in.logIn after your auth system confirms the session. Do not call logIn speculatively. The typical trigger is your auth state listener firing with a signed in user. logIn returns both the user's current CustomerInfo and a created: Boolean that tells you whether this is a brand new RevenueCat customer.logOut only works on identified users. Calling logOut while the SDK is on an anonymous ID throws an error in every SDK (PurchasesErrorCode.LogOutWithAnonymousUserError or the iOS equivalent). Gate it behind your own "is signed in" flag.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, call logIn(appUserID) first, then restorePurchases() only if they also expect to pull a receipt from the current store account.logOut then logIn. If your app lets a user sign out and sign back in as someone else, call logOut() first, wait for it, then logIn(newId). Do not try to swap directly with a second logIn, since that will alias the two IDs together.Purchases.configure(…) must have run before logIn / logOut. If it has not, the SDK throws.Read the platform file that matches detection:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.mdEach platform file shows the logIn and logOut calls wired into a typical auth state observer.
Do not claim identity sync works until:
$RCAnonymousID: placeholder.logIn, remains attached to the signed in user (aliased, not lost).logOut while already anonymous is handled, not treated as a crash or a silent success.原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。