Data validation

As seen in the introduction section, we need to validate our data before saving it in the database to maintain data integrity and correctness. Firebase rules provide .validate expressions such as .read and .write to implement validation logic such as length of the field should be only this many characters or it must be of string data type.

Consider this example:

{
"rules": {
"users": {
"email": {
".validate": "newData.isString() && newData.val().length < 50"
}
}
}
}

The preceding validation rule for email field determines that the value of email field must be String and its length should be less than 30 characters.

It is important to note that validation rules do not cascade, so in order for the write to be allowed, all relevant validation rules must evaluate to true.

Now since we have a basic understanding of Firebase rules, let's deep dive into rules configuration.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset