Question

Firebase implementation, ERROR Cannot read property 'includes' of undefined

  • 16 September 2023
  • 1 reply
  • 68 views

Badge +3

Hello, 

Im am going through the firebase docs for the implementation and I am on the final stage, where I check the entitlements via the firebase claims with the code below

getAuth().currentUser.getIdTokenResult() .then((idTokenResult) => { // Confirm the user has a premium entitlement. if (!!idTokenResult.claims.activeEntitlements.includes("premium")) { // Show premium UI. showPremiumUI(); } else { // Show regular user UI. showFreeUI(); } }) .catch((error) => { console.log(error); });


When I go to check the active entitlements with the code like so console.log(idTokenResult.claims.activeEntitlements) it returns undefined and when I check the returned object of just console.log(idTokenResult.claims) activeEntitlements doesn’t exist. Also I enabled claims in the firebase setup

What can possibly be the fix for this? Thanks 


1 reply

Userlevel 6
Badge +8

Hey @resellology,

Since it sounds like the `activeEntitlements` property doesn’t exist, I think you’ll want to first check if that property exists before trying to access it. It’s possible the user hasn’t had any data synced at the point in time you’re checking.

If you’re just looking to check entitlement access on your device, it may be easier and more reliable to use our SDK directly: https://www.revenuecat.com/docs/customer-info

Reply