How can I make sure that a servervalue is written to firebase via firebase rules?
I am writing a message to the realtime database like so:
newMessageRef.set({
id: newMessageRef.key,
author: "Username",
content: "Message",
timestamp: firebase.database.ServerValue.TIMESTAMP
})
How can I make sure that the client doesnt modify my code and use a custom timestamp?
For this you can use the now variable in Firebase security rules like this:
{
"rules": {
"Messages": {
"$newMessageRef": {
"timestamp": {
".validate": "newData.val() === now"
}
}
}
}
}
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