Code
22
SDK error · code 22
What it means
logOutAnonymousUserError (code 22) means logOut was called while the current user is already anonymous, so there is nobody to log out. Call logOut only after a successful logIn, or check isAnonymous first. The error is harmless: the user stays anonymous, and no purchase or entitlement changes.
Code
22
iOS (Swift)
ErrorCode.log
Android (Kotlin)
PurchasesErrorCode.Log
Causes
logOut was called without a prior logIn, so the SDK still uses its anonymous ID (IdentityManager.swift).logOut ran twice in a row. The first call returned the user to anonymous, and the second one fails.logOut for users who never signed in, such as guests.Fix
Read Purchases.shared.isAnonymous on iOS or Purchases.sharedInstance.isAnonymous on Android, and call logOut only when it is false.
Call logIn after your user signs in and logOut after they sign out. Do not call logOut on app start.
Disable the sign-out button after the first tap, so the call runs once.
If the call is cleanup code, catch this code and treat it as success.
In your app
// Swift
do {
let result = try await Purchases.shared.purchase(package: package)
} catch let error as ErrorCode where error == .logOutAnonymousUserError {
// handle log out with an anonymous user
}
// Kotlin
if (error.code == PurchasesErrorCode.LogOutWithAnonymousUserError) { /* ... */ } On RevenueDot: RevenueDot is not involved. The SDK raises this error before it sends a request.
FAQ
Call logOut after a user who signed in with logIn signs out. Check isAnonymous first, because logOut on an anonymous user returns this error.
No. Nothing changes. The user is already anonymous, and their purchases stay on the anonymous customer.
In React Native, compare error.code with PURCHASES_ERROR_CODE.LOG_OUT_ANONYMOUS_USER_ERROR. In Flutter, convert the PlatformException with PurchasesErrorHelper.getErrorCode(e) and compare the result with PurchasesErrorCode.logOutWithAnonymousUserError.
Get started
RevenueDot answers the same SDK calls with the same error codes. Start free on RevenueDot Cloud, free up to $10,000 a month in tracked revenue.
Already have an account? Sign in · Prefer your own servers? Self-host free