26
30

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 5 years have passed since last update.

firestoreのセキュリティルールメモ

Posted at

firestoreの制限

セキュリティ目的などでfirestoreの権限を制限する事ができる。

service cloud.firestore {
  match /databases/{database}/documents {
    match /<some_path>/ {
      allow read, write: if <some_condition>;
    }
  }
}

基本的にはmatchでどのドキュメントかを指定して、allowでなにを許可するか、ifでその許可する際の条件を指定する。

複数の条件がtrueのとき

複数条件文にヒットした際はtrueになる。

ルール

  • read
    • get・・・一つのドキュメントを読める
    • list・・・複数のドキュメントをqueryとcollectionを使って読み込める
  • write
    • create
    • update
    • delete

投稿者のみに編集権限をもたせたい

service cloud.firestore {
  match /databases/{database}/documents {
    match /posts/{post} {
      allow delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true
    }
  }
}

26
30
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
26
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?