Skip to main content
Question

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

  • September 16, 2023
  • 1 reply
  • 140 views

Forum|alt.badge.img+4

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 

This post has been closed for comments

1 reply

cody
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 501 replies
  • September 20, 2023

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


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