如何只允许一个管理员用户编写 Firebase 数据库? [英] How to only allow one admin user to write Firebase Database?

查看:29
本文介绍了如何只允许一个管理员用户编写 Firebase 数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个只有我可以编写的 Firebase 数据库.所以没有用户将有权写任何东西.但是每个人都可以阅读.

I am trying to set up a Firebase database that only I can write. So no user will have permission to write anything. But everyone will be able to read it.

但是,我无法为其设置规则.我有一个使用电子邮件/密码登录创建的管理员用户,我知道它的 UID.假设我的 UID 是:dJrGShfgfd2

However, I could not set up the rules for it. I have one admin user that I created using Email/Password login, and I know its UID. Let's say my UID is: dJrGShfgfd2

我尝试了这两种方法,但它们不允许我写入数据库.

I tried these two methods, but they didn't allow me to write to database.

{
  "rules": {
    "events": {
      ".read": true,
      ".write": "auth.uid === 'dJrGShfgfd2'"
    }
  }
}

.

{
  "rules": {
    "users": {
      "$user_id": {
        ".read" : true,
        ".write": "$user_id === 'dJrGShfgfd2'"
      }
    }
  }
}

那么如何只允许一个具有特定 UID 的用户向数据库写入任何内容?

So how do I allow only one user with a specific UID to write anything to database?

推荐答案

这应该有效:

{
  "rules": {
    ".read": true,
    ".write": "auth.uid === 'dJrGShfgfd2'"
  }
}

世界上的每个人都可以读取数据,但只有具有 UID dJrGShfgfd2(和 具有管理权限的进程) 可以写入数据.

Everyone in the world will be able to read the data, but only the user with UID dJrGShfgfd2 (and processes with administrative access) can write the data.

这篇关于如何只允许一个管理员用户编写 Firebase 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆