如何存储每个用户的数据并防止其他人看到它们

Thi*_*ier 6 firebase firebase-security

我想知道 Firebase 是否可以实现以下功能:

  • 在 Firebase 应用程序中处理多个用户
  • 用户可以使用 OAuth2 和 Google 等外部提供商进行注册
  • 每个用户都有自己的数据集
  • 其他用户看不到特定用户的数据

Firebase 将在没有服务器端应用程序的前端 Web 应用程序中使用。

非常感谢您的帮助。

Mar*_*son 5

我认为您的所有要求都已满足。

查看文档:https : //www.firebase.com/docs/security/guide/user-security.html

在此处输入图片说明

稍加修改,您的安全规则可以如下:

{
  "rules": {
    "users": {
      "$user_id": {
        // grants write access to the owner of this user account
        // whose uid must exactly match the key ($user_id)
        ".write": "$user_id === auth.uid",
        ".read": "$user_id === auth.uid"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 聪明:```".write" : "root.child('users').child($user_id).child('friends').hasChild(auth.uid)"```(感谢分享) (2认同)