RevenueCat / purchases-flutter

Flutter plugin for in-app purchases and subscriptions. Supports iOS, macOS and Android.
https://www.revenuecat.com/
MIT License
607 stars 168 forks source link

logOut() throws "user is anonymous" error even if I check Purchases.isAnonymous first #934

Open lukepighetti opened 9 months ago

lukepighetti commented 9 months ago

If I check that the current session is not anonymous before calling Purchases.logOut(), I still get a "user is anonymous" error

if (!await Purchases.isAnonymous) Purchases.logOut();

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(22, LogOut was called but the current user is anonymous., {message: LogOut was called but the current user is anonymous., readableErrorCode: LOGOUT_CALLED_WITH_ANONYMOUS_USER, code: 22, underlyingErrorMessage: , readable_error_code: LOGOUT_CALLED_WITH_ANONYMOUS_USER}, null)

RCGitBot commented 9 months ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

mshmoustafa commented 9 months ago

Hi @lukepighetti, That's strange, any chance you could print the result of !await Purchases.isAnonymous as well as the app user ID?

AlexSeednov commented 9 months ago

Hi guys! Also saw this strange situation couple weeks ago. As I understood it's not a regular issue, just happened sometimes.

Maybe it's better to not to throw exception in this case? Just do the same checking await Purchases.isAnonymous inside logOut function and make a log out only if it's false without throwing exceptions or logging errors otherwise.

Anyway, thanks for your time and your package! It's awesome

mshmoustafa commented 8 months ago

Hi all,

After discussing with the mobile engineering team we decided that since calling logOut with an anonymous iD is a non-successful state, we're going to keep this as an exception.

One thing that came up: you may have to use if (!await Purchases.isAnonymous) await Purchases.logOut();

lukepighetti commented 7 months ago

I'm having a hard time understanding the last message posted.

if (!await Purchases.isAnonymous) Purchases.logOut();

and

if (!await Purchases.isAnonymous) await Purchases.logOut();

Should both work

and ideally, Purchases.logOut() would just make this check internally so we don't have to

orkun1675 commented 1 week ago

We are still seeing this error in our Crashlytics logs.

Here is the code block that we are using:

try {
  if (!(await Purchases.isAnonymous)) {
    await Purchases.logOut();
    _log.info(
        'Logged out from RevenueCat since Firebase user is null.');
  }
} on PlatformException catch (e) {
  PurchasesErrorCode errorCode = PurchasesErrorHelper.getErrorCode(e);
  // Log error.
}