亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Firebase 安全規則未顯示任何數據

Firebase 安全規則未顯示任何數據

慕田峪9158850 2022-12-09 15:38:46
我正在努力保護我的 Firebase。我做了這樣的事情來保護我的用戶列表。rules_version = '2';service cloud.firestore {match /databases/{database}/documents {     match /about/{id} {        allow read: if true;        allow write: if request.auth.uid != null;    }match /avantages/{id} {        allow read: if true;        allow write: if request.auth.uid != null;    }match /blog/{id} {        allow read: if true;        allow write: if request.auth.uid != null;    }match /customers/{id} {        allow read: if true;        allow write: if request.auth.uid != null;    }match /lowersection/{id} {        allow read: if true;        allow write: if request.auth.uid != null;    }match /middlesection/{id} {        allow read: if true;        allow write: if request.auth.uid != null;    }match /topsection/{id} {        allow read: if true;        allow write: if request.auth.uid != null;    }    match /users/{userId} {allow read: if isOwner(userId);allow write: if isOwner(userId);}}function isOwner(userId) {return request.auth.uid == userId; }}但是一旦我這樣做了,我的網站上就沒有數據顯示了。目標是讓每個人都可以讀取數據(用戶集合除外),但數據只能由登錄用戶寫入。根據要求,下面是來自 Angular 應用程序的代碼,它允許它獲取數據并發回更新后的數據。getTopSectionMain() {return   this.firestore.collection('topsection').doc('content').collection('main').snaps hotChanges();}updateTopSectionMain(dataID: any, data: any) {this.firestore.doc('topsection/content/main/' + dataID).update(data);}這是來自我的內容服務。任何幫助,將不勝感激。
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

您的問題似乎來自您閱讀sub-collections 中的文檔這一事實。


讓我們以集合為例topsection。您有如下安全規則:


match /topsection/{id} {

    allow read: if true;

    allow write: if request.auth.uid != null;

}

但是您查詢文檔如下:


getTopSectionMain() {

    return   this.firestore.collection('topsection').doc('content').collection('main').snaps hotChanges();

}

這意味著您查詢集合中文檔的main子集合的content文檔topsection。


如文檔中所述:“安全規則僅適用于匹配的路徑,因此在(父)集合上定義的訪問控制不適用于(子)子集合?!?/p>


您需要通過添加遞歸通配符來調整規則

match /topsection/{document=**} {

        allow read: if true;

        allow write: if request.auth.uid != null;

}

或指定每個子集合,如:


match /topsection/{id} {

    match /main/{id} {

        allow read: if true;

        allow write: if request.auth.uid != null;

    }

}

由于您沒有使用通配符來聲明頂級集合的安全規則,因此您最好使用第二個選項。


查看完整回答
反對 回復 2022-12-09
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號