0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Firestoreのセキュリティルール&JSでのリスナー用のクエリ実装(配列のフィールドに特定値を含む)

Last updated at Posted at 2022-07-28

前提

  • フィールド uidsuid が含まれている場合、 read を許可する。
    ※とりあえず、 read にしているけど write とかも同様
  • クライアント側(Firestore をリッスンする側は JavaScript の FirebaseSDK を使用する。
  • リッスンの条件は 「フィールド uidsuid が含まれている場合」

実装

データ構成

image.png

Firestoreのセキュリティルール

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if request.auth != null && request.auth.uid in resource.data.uids;
      allow write: if request.auth != null;
    }
  }
}

FirebaseSDKでのクエリ

const hogehogeRef = collection(db, "hogehoge");
const q = query(hogehogeRef, where("uids", "array-contains", "UIDの文字列",),);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?