SDK error · code 22

logOutAnonymousUserError (error code 22): Log out with an anonymous user

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.logOutAnonymousUserError

Android (Kotlin)

PurchasesErrorCode.LogOutWithAnonymousUserError

Causes

Why the SDK returns logOutAnonymousUserError

  • 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.
  • Your sign-out code calls logOut for users who never signed in, such as guests.
  • The Android SDK raises the same error as LogOutWithAnonymousUserError (IdentityManager.kt).

Fix

How to fix logOutAnonymousUserError

  1. 01

    Check isAnonymous first

    Read Purchases.shared.isAnonymous on iOS or Purchases.sharedInstance.isAnonymous on Android, and call logOut only when it is false.

  2. 02

    Pair logIn and logOut

    Call logIn after your user signs in and logOut after they sign out. Do not call logOut on app start.

  3. 03

    Guard double taps

    Disable the sign-out button after the first tap, so the call runs once.

  4. 04

    Ignore the error if you must

    If the call is cleanup code, catch this code and treat it as success.

In your app

How to handle it in code

  • Do not retry. The state it asks for already holds.
  • Treat it as success in sign-out flows. The user is anonymous, which is what you wanted.
  • No access changes. Entitlements stay with whatever ID the SDK uses now.
Match the errorSwift · Kotlin
// 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

logOutAnonymousUserError: questions people ask

How do I log out a user in RevenueCat?

Call logOut after a user who signed in with logIn signs out. Check isAnonymous first, because logOut on an anonymous user returns this error.

Does logOutAnonymousUserError lose any purchases?

No. Nothing changes. The user is already anonymous, and their purchases stay on the anonymous customer.

How do I check for logOutAnonymousUserError in React Native and Flutter?

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

Keep the RevenueCat SDK. Change the backend.

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