Skip to main content
Question

Firebase claims not being removed after subscription expiration on previous account if user creates a new account

  • October 22, 2024
  • 0 replies
  • 34 views

Forum|alt.badge.img+1
I'm implementing a subscription system using RevenueCat with React Native Expo and Firebase, utilizing the RevenueCat Firebase extension. My current flow is:
  • User signs in anonymously with Firebase (and implicitly with RevenueCat).
  • User encounters a paywall and makes a purchase.
  • User is redirected to a signup menu with the following sign up options email, Google, Apple.
  • When the users signs up we do a account firebase upgrade from anonymous using linkWithCredential.
Issues I'm facing:
1. If, after upgrading their account, the user chooses to create a new account with an email and password (now it would not get linked instead this is a entirely new account), the revenueCat subscription appears on both the old and new accounts ( i believe this happens after one of these methods are ran 

 await Purchases.restorePurchases();
 await Purchases.syncPurchases();
I am not sure why though, do these methods call the firebase cloud function? and should I not call them? and if I should not call them then this would not be very safe as we would just be explosives for vulnerability to the front end) Now appearing on both account is bad, but what is even worse is that it seams like:

  • The old account's Firebase custom claims aren't being removed when RevenueCat stops tracking it, (so after login on to the new account the old account subscription/entitlement is stuck in active even though it's past expiration date because the revenuecat firebase claim is not removed, I could potentially solve this by just looking at the firestore collection, but I am not sure if that would be good practice)
  • Unsure if calling Purchases.logIn(user.uid) and Purchases.syncPurchases() after linking is necessary or causing issues. ( I am calling the Purchases.logIn(user.uid)  after the user has signed up on either one of the sign up methods, where the user.uid would be the firebase uid)
My understanding is that we're dealing with three states that need to be synced:
  • Local Apple device subscription state
  • RevenueCat subscription state
  • Firebase subscription state (custom claims/Firestore)
Questions:
  • How can we ensure that when a new account is created (not linked), the subscription is transferred or not duplicated?
  • Is it correct to only sync purchases if the Firebase UID matches the RevenueCat user ID?
  • How can we ensure that old, unlinked accounts have their Firebase custom claims removed?
Any insights on best practices for managing these states across anonymous and authenticated users would be greatly appreciated. Also any links to resources more about this would be much appreciated.
This post has been closed for comments

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings