revenuecat-identify-user
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineserevenuecat-identify-user: connect RevenueCat to your auth system
revenuecat-identify-user:将RevenueCat与您的认证系统关联
Use this skill when the user wants to call / on the RevenueCat SDK so that their app users line up with RevenueCat subscribers. This skill does not cover initial SDK setup (see ), purchases (), or gating ().
logInlogOutintegrate-revenuecatrevenuecat-purchase-flowrevenuecat-entitlements-gate当用户希望在RevenueCat SDK上调用/,使应用用户与RevenueCat订阅者保持一致时,可使用此技能。本技能不涵盖SDK初始设置(详见)、购买流程()或权限管控()。
logInlogOutintegrate-revenuecatrevenuecat-purchase-flowrevenuecat-entitlements-gate1. Detect the platform
1. 检测平台
Inspect the working directory and pick the first match, from top to bottom:
- React Native: has a
package.jsonentry, orreact-native-purchasesas a dependency → readreact-native. Ifplatforms/react-native.mdis also a dependency, note it as an Expo project.expo - Flutter: exists at the project root → read
pubspec.yaml.platforms/flutter.md - Kotlin Multiplatform: contains a
build.gradle.ktsmultiplatform source sets block, or depends onkotlin { … }→ readcom.revenuecat.purchases:purchases-kmp*.platforms/kmp.md - Android (native): applies
build.gradle(.kts)(and is not KMP) → readcom.android.application.platforms/android.md - iOS (native): ,
Package.swift,*.xcodeproj, or*.xcworkspaceat the project root → readPodfile.platforms/ios.md
If several match (e.g. an 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.
ios/检查工作目录,从上到下选择第一个匹配项:
- 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)(且非KMP项目)→ 阅读com.android.application。platforms/android.md - iOS(原生):项目根目录存在、
Package.swift、*.xcodeproj或*.xcworkspace→ 阅读Podfile。platforms/ios.md
如果有多个匹配项(例如Flutter项目中包含文件夹),选择最外层的项目,即拥有构建权限的项目。若仍存在歧义,请询问用户想要配置哪个平台。
ios/2. Shared concepts (all platforms)
2. 通用概念(全平台)
- Anonymous by default. Before is called, RevenueCat assigns a stable anonymous ID prefixed
logIn. Purchases made while anonymous are aliased onto the real$RCAnonymousID:the first timeappUserIDis called with it, so there is no "lost purchase" risk from letting users buy before signing in.logIn - 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 after your auth system confirms the session. Do not call
logInspeculatively. The typical trigger is your auth state listener firing with a signed in user.logInreturns both the user's currentlogInand aCustomerInfothat tells you whether this is a brand new RevenueCat customer.created: Boolean - only works on identified users. Calling
logOutwhile the SDK is on an anonymous ID throws an error in every SDK (logOutor the iOS equivalent). Gate it behind your own "is signed in" flag.PurchasesErrorCode.LogOutWithAnonymousUserError - Restore is not login. 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
restorePurchases()first, thenlogIn(appUserID)only if they also expect to pull a receipt from the current store account.restorePurchases() - Account switching is then
logOut. If your app lets a user sign out and sign back in as someone else, calllogInfirst, wait for it, thenlogOut(). Do not try to swap directly with a secondlogIn(newId), since that will alias the two IDs together.logIn - Configure first. must have run before
Purchases.configure(…)/logIn. If it has not, the SDK throws.logOut
- 默认匿名状态。 在调用之前,RevenueCat会分配一个以
logIn为前缀的稳定匿名ID。匿名状态下进行的购买,会在首次使用真实$RCAnonymousID:调用appUserID时关联到该ID上,因此允许用户在登录前购买不会有“购买丢失”的风险。logIn - 切勿使用邮箱、电话号码或连续数据库ID作为appUserID。 使用稳定的不透明值,例如后端的用户UUID或用户ID的哈希值。RevenueCat将该ID视为不透明字符串,后续难以修改。
- 在认证系统确认会话后调用。 请勿随意调用
logIn。典型触发时机是认证状态监听器检测到用户已登录。logIn会返回用户当前的logIn以及一个CustomerInfo值,用于告知您该用户是否是全新的RevenueCat客户。created: Boolean - 仅对已识别用户生效。 当SDK处于匿名ID状态时调用
logOut,所有SDK都会抛出错误(logOut或iOS端等效错误)。请在您自己的“已登录”标记为真时才允许调用该方法。PurchasesErrorCode.LogOutWithAnonymousUserError - 恢复购买不等于登录。 会向应用商店请求当前收据,并将其附加到当前RevenueCat用户上。它不会切换身份。如果用户在新设备上登录,请先调用
restorePurchases(),仅当用户需要从当前商店账户获取收据时,再调用logIn(appUserID)。restorePurchases() - 账户切换需先再
logOut。 如果您的应用允许用户退出并以其他身份重新登录,请先调用logIn,等待完成后再调用logOut()。请勿尝试直接通过第二次调用logIn(newId)来切换,因为这会将两个ID关联在一起。logIn - 先配置再调用。 必须在
Purchases.configure(…)/logIn之前执行。如果未执行,SDK会抛出错误。logOut
3. Implementation
3. 实现步骤
Read the platform file that matches detection:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
Each platform file shows the and calls wired into a typical auth state observer.
logInlogOut阅读与检测结果匹配的平台文件:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
每个平台文件都展示了如何将和调用接入典型的认证状态监听器。
logInlogOut4. Verify
4. 验证步骤
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 placeholder.
$RCAnonymousID: - 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 , remains attached to the signed in user (aliased, not lost).
logIn - Calling while already anonymous is handled, not treated as a crash or a silent success.
logOut
在满足以下条件之前,请勿宣称身份同步功能正常:
- 在RevenueCat控制台中,测试用户的客户页面显示的appUserID与您后端使用的完全一致,而非占位符。
$RCAnonymousID: - 退出登录后,ID会重置为新的匿名用户;以其他账户登录时,会切换到该账户的购买记录(如果是新账户则显示无记录)。
- 匿名状态下进行的购买,在调用后仍会关联到已登录用户(已关联,未丢失)。
logIn - 在已匿名状态下调用时能被正确处理,不会导致崩溃或静默成功。
logOut