I'm using Firebase and have the following schema for users
:
{
"uid": "randomUID",
"domain": "@domain1"
}
and I have a collection domains
containing all the domains of users like so:
{
"@domain1": {
"uid": "randomUID"
}
}
I'm trying to use Firestore security rules in order to prevent creation of new users that have the same domain as a pr-existing. This is what I have so far:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{Id} {
allow read: if true;
allow create: if exists(/databases/$(database)/documents/domains/$(resource.data.domain)) == false;
}
}
But it doesn't work. I've also tried the following combinations of the allow create rule but none of them worked:
if !exists(/databases/$(database)/documents/domains/$(resource.data.domain));
and
if !exists(/databases/$(database)/documents/domains/$(request.resource.data.domain));
Any ideas or suggestions? Debugging the security rules is tricky since there's no debugger yet.