5

I am trying to allow my users to set an expiration timer (up to 2 hours) for data stored in Firebase. The data needs to be deleted once the timer expires, but I've been having trouble finding a solution that will accomplish this even if the app is terminated. The timer is also displayed to the user and needs to be kept up to speed when the user re-opens the app. Also, other users shouldn't be able to see the data if it expired while the creator's app was terminated.

The only thing I could think of was using timestamp comparisons, which seems really inefficient. What's the best approach to this? Thank you in advance!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Julian Lee
  • 293
  • 1
  • 11
  • There is no server-side time-to-live support in the Firebase Database. You'll have to run a script (client-side or on your own "server"). See http://stackoverflow.com/questions/32004582/delete-firebase-data-older-than-2-hours – Frank van Puffelen May 07 '16 at 03:37
  • does each user have their own timer and data? In other words, can users see each other's data and/or set a timer for other users? – Jay May 07 '16 at 16:03
  • Users can see each others data (assuming it hasn't expired) but cannot set a timer for other users. – Julian Lee May 07 '16 at 17:52
  • @FrankvanPuffelen Is that still the case today? –  Jun 02 '17 at 10:04
  • Yes. The only difference is that you can now run such a script on Cloud Functions for Firebase. – Frank van Puffelen Jun 02 '17 at 10:30
  • @FrankvanPuffelen Thanks for your reply. I haven't found a how-to or tutorial to build such a script (also in the Firebase Documentation). Can you please link us to one or tell us how to do it in an answer? Appreciate it! It'd be very useful. –  Jun 02 '17 at 10:35
  • @FrankvanPuffelen The only thing I found is this useless answer: https://stackoverflow.com/a/42772618/5113094 –  Jun 02 '17 at 10:43
  • Interesting. Because that answer is precisely what I used when I recently needed to do scheduled maintenance with a Cloud Function. Between that answer (also presented in [this sample](https://github.com/firebase/functions-samples/tree/master/delete-unused-accounts-cron) and mentioned in [this blog post](https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html)) and [my answer here](https://stackoverflow.com/questions/32004582/delete-firebase-data-older-than-2-hours) you have all the necessary parts. – Frank van Puffelen Jun 02 '17 at 11:06
  • If you're having problems making it work, share the [minimal steps to reproduce that problem in a new question](http://stackoverflow.com/help/mcve). – Frank van Puffelen Jun 02 '17 at 11:06

0 Answers0