Search code examples
revenuecat

Check if Users Subscription is still active with the RevenueCat API


Whats the best way to check if a users subscription is still active with the RevenueCat API?

I can get the entitlements of a user but it seems like, after the expiration of the subscription, the entitlement is still in the entitlements object.

"entitlements": {
      "premium_monthly": {
        "expires_date": "2019-10-27T17:27:59Z",
        "product_identifier": "app_premium_monthly",
        "purchase_date": "2019-10-27T17:21:24Z"
      }
    },

The only way I see to do this is something like this:

                const exp = new Date(res.data.subscriber.entitlements.premium_monthly.expires_date)
                const now = new Date();
                if (exp.getTime() < now.getTime()) {
                    // Subscription is no longer valid
                }

Is that the intended way to do this or is there a better one?


Solution

  • Yes, that's the way to check it. Compare current time with the expiration time provided by RevenueCat's API.