prabin maharjan
prabin maharjan

Reputation: 887

How to limit the user to play quiz from firestore only once per day?

I am developing a Flutter quiz app for learning purposes using Cloud Firestore. The app is working fine, but the problem is that same user can read and play quiz multiple number of times in a single day. I want to restrict users to play quizzes only once per day. My research is not helping me out, so I decided to seek help here. How can I impose restrictions on the number of times the quiz played by users per day? Any help will be appreciated a lot.

Upvotes: 0

Views: 205

Answers (3)

Unknown
Unknown

Reputation: 31

yes shared preference will help you here is the example.

Upvotes: 1

Alex Mamo
Alex Mamo

Reputation: 138924

I want to restrict users to play the quiz only once per day.

The simplest solution I can think of is to create a new field in each User object called "readyToPlay". This field should have the initial value of "true". As soon as the user finishes the first game, change the value of the field to "false". Then simply restrict the possibility to play the game according to this field. So you have to check at the beginning of each game, against this newly added field.

To reset the value of this field to "true", every single day, I recommend you write a function in Cloud Functions for Firebase and call it once a day using Cloud Scheduler, as explained in my answer from the following post:

Upvotes: 1

Why_So_Ezz
Why_So_Ezz

Reputation: 158

if I interpreted your problem correctly then this will work for you...

  • when a user enters the game you should set the variable in shared preference like {'isJoined' : 'true' , 'joinedTime': 'dd-mm-yyyy'}
  • now in this case you can have multiple logic I will suggest you if your time is fixed then you can compare the current time with last joined time.

Upvotes: 2

Related Questions