![](/img/trans.png)
[英]My flutter iOS app hasn't been released yet. How can I know my firebase dynamic link works to open Appstore if the app isn't installed yet?
[英]How to add firebase security rules for Flutter collection that hasn't been created yet
我正在使用 Firebase Auth 和 Firestore 數據庫。 我正在嘗試向 Firebase 數據庫添加安全規則,以允許用戶閱讀、更新、創建和刪除帖子。 當我在 Rules Playground 中測試我的規則時,訪問被拒絕,所以我知道我沒有正確編寫規則。 這是添加安全規則之前的數據庫圖像。
現在我已經添加了安全規則,沒有創建帖子集合,並且我在以下規則游樂場中收到錯誤消息:
> Simulated write denied
> Simulated read denied
我得到以下控制台錯誤:
以下 _CastError 被拋出構建 CommunityPage(dirty, dependencies: [_InheritedProviderScope<UserProvider?>], state: _CommunityPageState#f5d54): type 'Null' is not a subtype of type 'String' in type cast
在應用程序中,所有用戶都應該能夠創建帖子以添加到他們的個人資料中。 當用戶有一個新創建的帳戶時,他們還沒有任何帖子,所以我試圖弄清楚如何包含安全規則,允許顯示帖子的頁面出現,即使它沒有任何內容時創建了一個新用戶。 我已經查看了 SO 線程和 Firebase 文檔,但由於我是 Flutter 和 Firebase 的新手,所以我無法弄清楚。
任何幫助將不勝感激。 謝謝你。
我們可以在 Rules Playground 中看到:
read
規則使用write
isSignedIn()
function 檢查request.auth
object 是否不是null
;您應該在 Rules Playground 中激活身份驗證模擬,以便將isSignedIn()
function 評估為true
。
請注意,Playground 右側顯示的錯誤很可能顯示了與此問題相對應的消息,但我們沒有在您的屏幕截圖中看到它。
根據您的評論更新:
請注意, request.resource
只能用於write
規則(請參閱文檔):這可能解釋了read
規則的問題(問題底部的屏幕截圖)。 你必須做:
allow read: if isSignedIn() && request.auth.uid == resource.data.uid
注意上面的規則意味着在post
文檔中有一個名為uid
的字段。
對於create
rule error: are you sure you pass the user's uid as the field named uid
in the new created document?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.