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

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

问题描述

我试图建立一个只有我能写的Firebase数据库。所以没有用户将有权写任何东西。但是每个人都可以阅读。



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



我试过这两种方法,但是他们不允许我写

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


$ b



  {
规则:{
users:{
$ user_id:{
.read:true,
.write:$ user_id == ='dJrGShfgfd2'
}
}
}
}


$ b $那么如何才能让一个具有特定UID的用户向数据库写入任何内容呢?

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

世界上的每个人都可以读取数据,但只能读取用户与UID dJrGShfgfd2 (和进程管理访问权限)可以写入数据。


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.

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'"
      }
    }
  }
}

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

解决方案

This should work:

{
  "rules": {
    ".read": true,
    ".write": "auth.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天全站免登陆