I'm considering to use Firebase for a project but can't seem to find any informations on server-side data validation.
Lets say i'm making a game and a player deals damage to another player i would like to validate the following:
Is it possible to validate this kind of stuff /Adding serverside logic directly with Firebase or do i have to make an intermediate-server, basically smashing the whole point in using Firebase in the first place?
Thanks in advance Jonas
Validating data is definitely possible with Firebase. It is part of its "security" rules, for which the documentation can be found here and here.
A simple example from that last documentation link:
a sample .validate rule definition which only allows dates in the format YYYY-MM-DD between the years 1900-2099, which is checked using a regular expression.
".validate": "newData.isString() &&
newData.val().matches(/^(19|20)[0-9][0-9][-\\/. ](0[1-9]|1[012])[-\\/. ](0[1-9]|[12][0-9]|3[01])$/)"
You can build pretty complicated validation rules. In case you need those, you might want to have a look at Firebase's blaze compiler. It translates a higher-level language into Firebase's relatively low-level rules. The author of the blaze compiler originally wrote it for your second and third use-case and wrote an article about it here.
I hope these are enough to get you started. If you get stuck, just post a question with the rules you tried.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With