I\'m struggling with Firestore security rules. I want to check on a value that needs the replace function, i.e. an e-mail address. I can find some documentation in the gener
A little late, but you can simulate the replace function on a string with this one :
function replace(string, replace, by) {
return string.split(replace).join(by);
}
So you need to define this function in your firestore.rules file and then you can call replace(request.auth.token.email, '.' , ',')
to get the same result as request.auth.token.email.replace('.' , ',')
in javascript.
There are two reasons why you might have been having issues.
replace
function was added to Security Rules after you asked your question.replace
function uses regular expressions for the first argument and so matching on '.'
will match literally everything.Consider instead using: request.auth.token.email.replace('\\.' , ',')
var emailSanitized = email.replace('.' , '.'); db.collection('someCollection').where('members.' + emailSanitized, '==', 'admin')