yucatio@システムエンジニア

趣味で作ったものいろいろ

データベースルールファイル(database.rules.json)の変更と反映 (STEP 3 : 他のユーザのタスクが見れるタスク管理アプリを作成する - React + Redux + Firebase チュートリアル)

★前回の記事

yucatio.hatenablog.com

データベースルールファイルを変更します。

todosのルール

STEP 3では他のユーザのタスクは見れるので、そのように変更します。

database.rules.json

{
  "rules": {
    "todos" : {
      "$uid": {
        ".read": true, // 変更
        // 後略
      }
    }
  }
}

recentUpdatedTodosのルール

/recentUpdatedTodosに最近更新されたタスクを保存するので、設定を追加します。

database.rules.json

{
  "rules": {
    // 中略
    "recentUpdatedTodos": {  // 追加
      ".read": true,
      ".write": false  // #1
    },
    "$other": { ".validate": false }
  }
}
  • recentUpdatedTodosには、Cloud Functionsからのみ書き込むので、書き込み権限はfalseになっています。

データベースルールのFirebaseへの反映

ファイルを保存して、ルールをFirebaseに反映します。

$ firebase deploy --only database

=== Deploying to 'todo-sample-xxxxx’…

i  deploying database
i  database: checking rules syntax...
✔  database: rules syntax for database todo-sample-xxxxx is valid
i  database: releasing rules...
✔  database: rules for database todo-sample-xxxxx released successfully

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/todo-sample-xxxxx/overview

反映されました。

★次回の記事

yucatio.hatenablog.com

★目次

yucatio.hatenablog.com