Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference of Firebase authentication custom claims and Firestore document with no write access?

I'm looking for the difference between Firebase authentication with custom claims and a private Firestore document for each user with no write permissions.

The use case I am facing is a SaaS solution with 3 stripe plans. Each stripe plans has different properties. A user should be restricted to the plan they are subscribe to.

The only difference I see is that custom claims only require on call to Firebase while a document in Firestore would require 2 (auth + get user private data).

Are there any other differences I'm missing?

like image 235
Andreas Tzionis Avatar asked Jan 30 '26 23:01

Andreas Tzionis


1 Answers

It sounds like you're trying to compare two security models:

  1. Store the payment plan information in a custom claim in the user's token.
  2. Store the payment plan in a non-writeable document in Firestore.

Some changes that come to mind:

  1. As you say the second option will require an extra read operation whenever the security rules need to be validated.
  2. Storing the information in the token makes each request from the user bigger, since the claim is in their token. So it uses more bandwidth.

But probably the most important one for making up you mind:

  1. A custom claim may not be immediately available on the client, since it depends on the token being refreshed, which may take up to an hour. The information in the database on the other hands is up to date as soon as you write it.

For more good tips around this, have a look at the video Five tips to secure your app.

like image 170
Frank van Puffelen Avatar answered Feb 01 '26 14:02

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!