I have this firebase security rule:
".validate": "newData.val().length < 2"
When the new data.length is > 2, Firebase returns a error that says "PERMISSON_DENIED".
I would like to know if there is a way to get a error info like this "the new data is to long".
Thanks
Firebase Security Rules stand between your data and malicious users. You can write simple or complex rules that protect your app's data to the level of granularity that your specific app requires.
Firebase uses API keys only to identify your app's Firebase project to Firebase services, and not to control access to database or Cloud Storage data, which is done using Firebase Security Rules. For this reason, you do not need to treat API keys for Firebase services as secrets, and you can safely embed them in client code.
Firebase Realtime Database Rules leverage JSON in rule definitions, while Cloud Firestore Security Rules and Firebase Security Rules for Cloud Storage leverage a unique language built to accommodate more complex rules-specific structures.
If you already have a secure sign-in system, whether a custom system or a third-party service, you can use your existing system to authenticate with Firebase services. Create custom JWTs from a trusted environment, then pass the tokens to your client, which uses the token to authenticate ( iOS+ , Android, Web , Unity, C++ ).
Firebase security rules return the same error, no matter what part failed. You have no control over the error message. If you're troubleshooting why an operation is failing, you can use the Simulator in your Firebase dashboard. But that doesn't seem what you're looking for.
Showing a more intelligent error message to the user is a great idea though. But I'd recommend doing that by validating the data before you send it to Firebase. So perform client-side validation and only send the data to Firebase if it passes the validation.
Better yet: don't allow the user to enter more than 2 characters.
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