在我的新應用程式中,有一系列專案在 Firestore 中有成本。以下是我用來保護這些檔案的規則:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /projects/{project} {
function isSignedIn() {
return request.auth != null;
}
function isAdmin() {
return isSignedIn() && get(/databases/(database)/documents/users/$(request.auth.uid)).data.isAdmin) == true);
}
allow read: if isSignedIn();
allow create, update, delete: if isAdmin();
}
}
}
當我嘗試部署此規則集時,出現以下錯誤:
Error: Compilation errors in firestore.rules:
[E] 11:41 - Missing 'match' keyword before path.
[E] 11:51 - Forward slash '/' found where identifier or binding expected.
[E] 11:52 - mismatched input '(' expecting {'{', '/', PATH_SEGMENT}
[E] 11:62 - Missing 'match' keyword before path.
[E] 11:62 - Unexpected '/documents'.
[E] 11:78 - Forward slash '/' found where identifier or binding expected.
[E] 11:79 - mismatched input '$' expecting {'{', '/', PATH_SEGMENT}
[E] 11:98 - token recognition error at: '`'
[E] 23:1 - Unexpected '}'.
基本上它不喜歡這get條線。但我得到了公司的FireStore檔案的這一權利了這里。有沒有人知道為什么這可能不起作用?
uj5u.com熱心網友回復:
你有一些小錯誤:
- 你有兩個不需要
) - 你忘記了
$之前database
嘗試這個:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /projects/{project} {
function isSignedIn() {
return request.auth != null;
}
function isAdmin() {
return isSignedIn() && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true;
}
allow read: if isSignedIn();
allow create, update, delete: if isAdmin();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/349397.html
