0

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I would rather go for the client side one because I want to avoid cloud functions cold starts. – AhmedSalem016 Dec 20 '22 at 07:17
  • Though I have one more question please: Is it save to do such this on the client side? is there a possibility that a user could tweak the code and disable the decrement request that is being sent after each save request? – AhmedSalem016 Dec 20 '22 at 07:19
  • If you read the answer I linked, it shows how to implement security rules that will reject such code tweaks. – Frank van Puffelen Dec 20 '22 at 15:10