[英]Can't figure out how to write proper security rules in firebase
我開始使用 firebase 安全規則。 為了測試它,我正在編寫一個 function ,它獲取一個集合,然后從集合中獲取一個文檔,然后從文檔中獲取內容。 但是,當我嘗試從文檔中獲取內容時它失敗了。 function 如下
const testAccess = async () => {
const db = firebase.firestore();
try {
const usersCollection = await db.collection('users');
// console.log('usersCollection: ', usersCollection);
console.log('gets to here?');
const docRef = await usersCollection.doc('10158374072639913');
console.log('gets to here 2?')
const doc = await docRef.get();
console.log('gets to here 3!') // not getting to here!
} catch (e) {
console.log('error is : ', e);
}
}
當我運行 docRef.get() 時,我得到了錯誤,錯誤是:[FirebaseError:缺少或權限不足。]
我不確定為什么這不符合我的安全規則。
我的規則如下
rules_version = '2';
service cloud.firestore {
match /users/{user} {
allow read: if true;
match /{userInfo=**} {
allow read: if true;
}
}
}
這是我的數據庫架構
您缺少數據庫規則的根級別:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{user} {
allow read: if true;
match /{userInfo=**} {
allow read: if true;
}
}
}
}
如果沒有match /databases/{database}/documents
,規則不會匹配數據庫中的任何內容,因此每次讀取都會被拒絕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.