Background: In my flutter app it is possible for a user to sign out and another user to sign in without restarting the app. To support this feature the app calls Purchases.init whenever a user logs in. If the transition is non-sub to sub this works as expected IE the latter user sees their subscription. But this does not work if transition is sub to non-sub. In this case RC fails to update to non-sub and the non-sub user appears to have a subscription until they restart the app and the sub is gone.
Fix: reset all data when Purchase.init is called.
Best answer by sharif
To log a user in/out of your app, you should use the
logOut methods rather than calling
Purchases.setup multiple times. The setup method is meant to be called once, at the start of your app. That’s because it does a lot of setup that is required on iOS and Android to detect purchases made outside of your app (e.g. via App Store promoted in-app purchases.) So it doesn’t make sense to run all of that code multiple times.
To log in:
await Purchases.logIn(appUserId); // Fetches appUserId's info from RevenueCat
To log out:
await Purchases.logOut(); // clears local user data and creates an anonymous user
If you’re using v3.3.1 or earlier of the Flutter SDK then you need to use
await Purchases.identify(appUserId); // Fetches appUserId's info from RevenueCat
await Purchases.reset(); // clears local user data and identifies as an anonymous user
You can (and should) call
logOut whenever a user logs out and
logIn whenever a new user logs in. Calling
logOut wipes the cache on the device and resets RevenueCat to a near-fresh state, so it’s accomplishing what you’re trying to do by calling init multiple times.
For more information, take a look at our guide on identifying users.