purchases-flutter icon indicating copy to clipboard operation
purchases-flutter copied to clipboard

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

Open lukepighetti opened this issue 1 year ago • 7 comments

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)

lukepighetti avatar Jan 14 '24 19:01 lukepighetti

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

RCGitBot avatar Jan 14 '24 19:01 RCGitBot

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

mshmoustafa avatar Jan 17 '24 17:01 mshmoustafa

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

AlexSeednov avatar Jan 20 '24 14:01 AlexSeednov

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();

mshmoustafa avatar Jan 29 '24 14:01 mshmoustafa

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

lukepighetti avatar Feb 27 '24 18:02 lukepighetti