如何让所有人都能看到FireBase数据库中的图书列表

How to allow everyone to see the list of books in FireBase Database

我有一个 activity 可以注册并登录我的应用程序,之后用户可以添加一本书(标题、描述...)。

我还有一个 activity,其中包含书籍的列表视图。这个 activity 是主页,我想让每个人都能看到它,即使是没有登录的人。

 <activity
            android:name=".AccueilActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

如何允许所有人访问此 activity 并保持规则安全 "auth != null", 添加图书和其他操作?

我在 FireBase 数据库中的规则:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

节点书:

您可以像下面这样创建特定于节点的规则:

{
  "rules": {
    "books" : {
      ".read" : "true",
      ".write": "true"
    }
    "$other" : {
      ".read" : "auth != null",
      ".write": "auth != null"
    }
  }
}

这里 database.rules 不需要身份验证,而其余的则需要身份验证(由 $other 管理)。