1

I have free version and paid version on play store both have firebase authentication how to make sure not login for other email accounts except the account purchased

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Rajesh Wolf
  • 1,005
  • 8
  • 12

1 Answers1

2

Consider using custom user claims and then enforcing access via Firebase rules or checking the presence of the custom claims in the ID token if you are parsing it in your own server: https://firebase.google.com/docs/auth/admin/custom-claims

After a user signs in and completes their purchase, you can send the purchase credentials to your backend to process it along with the user's ID token. If both are verified, you set the custom claim for that user:

admin.auth().setCustomUserClaims(uid, {paidSubscriber: true}).then(() => {...

You then force the client to refresh their token to get the latest claims: currentUser.getIDToken(true)...

Now every request can check the user is authorized or not by checking the ID token.

{
  "rules": {
    "paidContent": {
      ".read": "auth.token.paidSubscriber === true",
      ".write": "auth.token.paidSubscriber === true",
    }
  }
}
bojeil
  • 29,642
  • 4
  • 69
  • 76