Identifying Users
AppActor manages user identity to associate purchases with the correct user across devices and sessions.
How Identity Worksโ
When you first configure the SDK in payment mode, AppActor automatically creates an anonymous user. You can then identify this user with your own user ID when they log in.
Identifyโ
Call identify to associate the current device with a known user ID. This is typically called after your user logs in.
- iOS
- Android
- Flutter
- React Native
// After user logs into your app
try await AppActor.shared.identify(appUserId: "user_123")
The identify call sends the following to the backend:
{
"appUserId": "user_123",
"platform": "ios",
"appVersion": "2.1.0",
"sdkVersion": "1.0.0",
"deviceModel": "iPhone15,2",
"osVersion": "17.0"
}
Call identify as early as possible after your user authenticates. This ensures purchases are correctly attributed to the user.
Loginโ
Use logIn to switch from the current user to a new identified user.
- iOS
- Android
- Flutter
- React Native
// Switch from current user to a different user
try await AppActor.shared.logIn(newAppUserId: "user_456")
Logoutโ
Call logOut when the user signs out of your app. This creates a new anonymous user.
- iOS
- Android
- Flutter
- React Native
// User signs out โ creates new anonymous user
try await AppActor.shared.logOut()
After logout, a new anonymous user is created. Any new purchases will be associated with this anonymous user until identify is called again.
Identity Flow Diagramโ
Best Practicesโ
- Call
identifyearly โ As soon as you know the user's ID, call identify - Use stable user IDs โ Use your backend's user ID, not email addresses
- Max 255 characters โ User IDs must be 255 characters or fewer
- Handle errors โ Identity calls can fail if the network is unavailable
do {
try await AppActor.shared.identify(appUserId: currentUser.id)
} catch {
// Handle error โ the SDK will continue with the anonymous user
print("Failed to identify user: \(error)")
}
Next Stepsโ
- Displaying Products โ Fetch and show offerings to users