I need to remove a plus signal at string returned by request.auth.phone_number. For that, I've tried to use the replace function, but I've received the following error: "Function not found error: Name: [replace].";
match /test/{id} {
allow read, update, delete, create: if request.auth != null && (resource.data.items[request.auth.token.phone_number.replace('+', '')] == true || resource == null);
}
This works fine when I run at Realtime Database. For instance:
"tests": {
"$uid": {
".write": "auth.uid.replace('+', '') === '5521999991234'"
}
}
Is there any way to use string functions like "contains(), replace(), toLowerCase()" and so on, in Cloud Firestore Databases?
Thanks
You could write a function like this :
function replace(string, replace, by) {
return string.split(replace).join(by)
}
and use it so..
replace('+3312312345', '+', '')
in your example :
match /test/{id} {
allow read, write: if request.auth != null &&
(resource.data.items[replace(request.auth.token.phone_number, '+', '')]
== true || resource == null);
}
// below your rules
function replace(string, replace, by) {
return string.split(replace).join(by)
}
Firestore security rules use a completely different language than Realtime Database.
You can see a list of all methods available on string objects in the API documentation. The only thing you are asking to do that's actually available is lower and matches.
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