0

I am using the firebase realtime database in my app. The functionality I am trying to achieve is simply to be able to change the value of a key in a time interval after its been changed.

More specifically, There is an authorized key and a boolean value in my database.

                          {
                          "user" : {
                             "UserID" : {
                             "Authorized" : "True"
                          }

This value gets changed to false after client side event happens

                          {
                          "user" : {
                             "UserID" : {
                             "Authorized" : "False"
                          }

Is it possible to be able to automatically change this value back to true within a time interval? For example, 'change back to true in 1 minute' This function would need to take place server side, for a timer will not be able to run once the user terminates the app. I believe firebase cloud functions may be of use, but I haven't been able to see exactly how it would be done.

I also looked into cron jobs, however, a cron job runs indefinitely for a certain time interval. In my case, after the value has been changed to false I just need it to change back to true once.

This functionality is similar to snapchats delete a snap in 24 hrs concept.

Im using Swift in Xcode. Any help or suggestion is very much appreciated!

  • check [this](https://stackoverflow.com/questions/42790735/cloud-functions-for-firebase-trigger-on-time). It might help. Another way is use ios background execution, but not practical for apps. It should be done on server side – xmhafiz Jul 01 '17 at 16:45
  • Scheduling some work to occur on a delay is a commonly requested feature. There is currently no way to do this within the Firebase platform. If this is a feature you would like, please file a feature request to vote for it: https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Jul 01 '17 at 16:51
  • @DougStevenson is setTimeout not supported in Cloud Functions? – J. Doe Jul 01 '17 at 16:55
  • You can use setTimeout, but you're effectively paying for all the time spent waiting, because you have to keep the function alive to handle the callback. Also, a function will time out by default after 1 minute, max 9 minutes if you configure it that way. – Doug Stevenson Jul 01 '17 at 16:58
  • I've been thinking of this alternative solution, Let me know what you think of it. Basically I would add another key : value to the structure. It would be the timestamp of when the value of authorize is changed (to false), when retrieving the value of authorize on the client side, it would also get the timestamp, I would then create a function to return the elapsed time from the timestamp and if it is passed 1 minute, then change the value of authorized back to true – Chris Mazile Jul 01 '17 at 17:22

0 Answers0