1
1

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

Firebaseのルール設定

Posted at

Firebase firestoreでのルール設定について[備忘録]

個人開発アプリにてFirebaseを利用しているのですが、認証機能をつけずに運用していたところ、急にデータを取れなくなったのでメモ。

新規firebaseProject作成後、ルール設定を(誰でも閲覧可能)にしていたところ、1,2ヶ月が過ぎた段階で以下の警告がでて動かなくなった。
スクリーンショット 2020-03-27 9.35.11.png
ちなみにその時のセキュリティソースが以下

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // This rule allows anyone on the internet to view, edit, and delete
    // all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // your app will lose access to your Firestore database
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2020, 3, 21);
    }
  }
}

これをいかに変更して、認証機能をつけることで解決。ちなみに匿名の認証機能を採用しました。(規約変更しないとなあ、、、)

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}

より良い解決方法ありましたら、ご教授いただけると幸いです。m(_ _)m

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?