Home > Back-end >  Counter Based Free-Trial in Firebase
Counter Based Free-Trial in Firebase

Time:12-20

I am building a React App that will be subscription based and it will be using Stripe. Briefly, it saves prompts (text) with a label

The problem I am facing is that I want to give the user 5 free saves and then ask him to subscribe. Can anyone help me know what is the best way to do this?

Thanks in advance

I thought of creating a counter in the user document and decrement it whenever a prompt is added. But the question is, should I do this in the client side after each save request or should I make an even-based cloud function that is triggered on document addition.

CodePudding user response:

There is definitive should here: you can do this either with only client-side code and security rules, or with a Cloud Function.

For an example of how to limit writes from a specific client, have a look at my answer here: How do I implement a write rate limit in Cloud Firestore security rules? You'll have to modify it to your use-case, but that should be easier than starting from scratch.

  • Related