0

Unfortunately, Firebase doesn't have out of the box an aging mechanism (delete old entries automatically). So, I am trying to implement one. However, I am stuck between two decisions:

  1. If a client fetch an old entry, he will delete automatically: I think it is the easiest for my context, but it doesn't look very secure to me.
  2. Implement a small script/program on a server that will check the full database and delete old entries.

I like the first solution, since it doesn't include deploying another server side application but I don't know if it could represent a risk.

What do you think is the best ? How can I secure the first solution to avoid any possible deletion of all items ? For the second solution, I don't won't to run the script from my computer and I don't want to pay for another sever to deploy the script, it it possible to to deploy it on Firebase ?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user655561
  • 659
  • 1
  • 9
  • 24
  • The answers on this post may give you some ideas: http://stackoverflow.com/questions/15990681/firebase-chat-removing-old-messages – Dr. Nitpick Jul 24 '16 at 17:03

1 Answers1

3

Deleting outdated items from the client has been covered before. See:

To secure this operation so that only outdated items can be removed, you can use Firebase Database security rules. Something like:

{
  "rules": {
    "messages": {
      "$message": {
        // only messages older than an hours can be remove
        ".write": "newData.exists() || data.child('timestamp').val() < (now - 3600000)",
      }
    }
  }
}

Running your own code on Firebase's servers can now be done with Cloud Functions for Firebase. There is also a sample that shows how to delete older data with Cloud Functions.

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