Reputation: 29
I wrote this but its not working:
isAdmin()
: not working
isLogin()
: working well
service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write : if false; } function isLogin() { return request.auth != null } function isAdmin() { return isLogin() && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true } // allow for only auth & is admin match /users/{userId} { allow read, write : if isAdmin(); } }
Thanks in advance
Upvotes: 1
Views: 234
Reputation: 1712
You need to pass the database variable as an argument in your function like this:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write : if false;
}
function isLogin() {
return request.auth != null
}
function isAdmin(database) {
return isLogin() &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true
}
// allow for only auth & is admin
match /users/{userId} {
allow read, write : if isAdmin(database);
}
}
}
Upvotes: 0