Create custom validation on Firebase Database Rules

♀尐吖头ヾ 提交于 2019-12-06 11:12:51

If you have a server, you can mint a custom token for Firebase Authentication to ensure your users are also identified within Firebase. They would then surface as auth and auth.uid in the Firebase Database security rules.

But in your current model, I'd recommend putting the secret into the key of the room:

  • order-test
    • UB8Hdazo834-4760_secret123
      • chat
        • Kifeisufsu23r name: "Bob", message: "How you doin?"
        • Ki4324ffs3fIF name: "Alex", message: "I am fine"

Now you can easily secure access so that only users that know both the room ID and the secret can access it:

{
  "rules": {
    ".write": false,
    "order-test": {
      "$roomIdAndSecret": {
        ".write": true
      }
    }
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!