Skip to content Skip to sidebar Skip to footer

How To Restrict Users From Writing More Than Once In A Database

I am working on a Bus booking app. So whenever a user books a ride I will store his credentials(name, email) for that particular ride. I need to restrict the number of bookings for

Solution 1:

To solve this, you should create another node named users in which you should add user objects. Each user object should have a property named numberOfRides with the default value of 0 (zero). After the first ride, increase that numer to 1 (one) and everytime a user wants to take another ride, check the value of this property. If it is 0 let the user get the ride otherwise, restrict him from getting the ride. Then, I recommend you write a function in Cloud Functions for Firebase that can set the value for the numberOfRides property for each user to 0 (zero). In the end just set a cron job to call this function by midnight. That's it!


Post a Comment for "How To Restrict Users From Writing More Than Once In A Database"