Skip to main content

When RevenueCat update firestore collection to indicate that subscription is cancelled claims are not updated.

Scenario to proof : 

-  Cancel your subscription and create a listener on the collection containing the subscription data.

-  Once subscription is updated by RevenueCat at ‘expiresDate’ your app will be notified.

-  Once notified call FirebaseAuth.instance.currentUser!.getIdTokenResult(true).
-  As you can see claims are not updated

Because of that, after subscription i can’t read some collections protected by firestore rules using claims.

Hi @enguerrand-arminjon-d1b39e! In this scenario, is the subscription immediately cancelled? Or have you set the subscription to “not renew”? Custom claims are based on entitlements, so if the subscription hasn’t fully expired, the entitlement will still be active for the user and won’t be removed.


When cancellation is cancelled and exceed limitation date (a canceled subscription can still be valid few minutes I know and that's why I listen Firestore) : firestore is well updated but claims are not at same times. If after store update I force refresh my claims using getIdTokenResult(true) I get the old claims... But if I wait a bit like 1 minutes I can we'll see claims updated...

 

So claims are asynchronously updated after store update instead of before or at same times...


Today I definitely remove all reference of firebase claims and I only use Firestore and firestore query inside my Firestore rules. That make few additional reads but I no longer have issues.

 

I really suggest to NOT follow RevenueCat doc with Firebase Claims. Both are not ready for PROD usages.

 

RevenueCat should I believe edit the documentation to not use RevenueCat Firebase Extension claims property as it didn't work. 


@enguerrand-arminjon-d1b39e Thanks for the additional information. Custom claims are set within the same function as the Firestore data. You can see in the main handler function of the integration that setCustomClaims is called just after the Firestore events and customers collections are updated.


An alternative can be to listen to events (from eventChannel) to know when refresh claims. Interesting, one key point is to achieve that also on app launch to avoid keep old claims → that required to implement a little logic.

Interessting i totaly forgot that revenuecat firebase extension is open source.

ty 🙂.


Reply