Firebase:具有完全权限的经过身份验证的用户在 root 上获得 PERMISSION DENIED
Firebase: Authenticated user with full permissions gets PERMISSION DENIED on root
在 Firebase 控制台中设置规则:
{
"rules": {
".read": true,
".write": true
}
}
运行 在 Chrome 控制台中:
> firebase.database().ref().set('foo');
Firebase 控制台的数据库选项卡现在反映 foo
。
在 Firebase 控制台中设置规则:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
运行 在 Chrome 控制台中:
> firebase.auth().signInAnonymously()
< A {W: 1, sa: undefined, u: null, oa: null, fb: nul…}
> firebase.database().ref().set('bar');
Uncaught (in promise) Error: PERMISSION_DENIED: Permission denied
Firebase 设置为允许匿名用户和 Google 用户,当我尝试读取或写入时,这两种用户都被拒绝许可。
编辑
我在这里添加了一个示例项目:
https://github.com/formido/react-firebaseui-web-Whosebug-question
如果我将规则设置为:
{
"rules": {
".read": "auth != null",
"44358340": { ".write": true }
}
}
...并登录,控制台会打印Timestamp written
.
如果我将规则设置为:
{
"rules": {
".read": "auth != null",
"44358340": { ".write": "auth != null" }
}
}
...并登录,控制台将打印 PERMISSION DENIED。
我知道的代码中最相关的部分是:
componentDidMount() {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
const ref = firebase.database().ref("/44358340");
if (user) {
const timestamp = firebase.database.ServerValue.TIMESTAMP;
ref.set(timestamp).then((error) => {
if (error) {
console.error(error);
}
else {
console.log('Timestamp written');
}
});
}
}
this.setState({loading: false, user});
});
}
它托管在亚马逊服务器上。我想也许我必须将 AUTH_DOMAIN
设置为 AWS 主机,但这并没有什么不同。
这是一个错误。参见 discussion starting here。
Fix here and it was deployed in Firebase 4.1.2.
在 Firebase 控制台中设置规则:
{
"rules": {
".read": true,
".write": true
}
}
运行 在 Chrome 控制台中:
> firebase.database().ref().set('foo');
Firebase 控制台的数据库选项卡现在反映 foo
。
在 Firebase 控制台中设置规则:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
运行 在 Chrome 控制台中:
> firebase.auth().signInAnonymously()
< A {W: 1, sa: undefined, u: null, oa: null, fb: nul…}
> firebase.database().ref().set('bar');
Uncaught (in promise) Error: PERMISSION_DENIED: Permission denied
Firebase 设置为允许匿名用户和 Google 用户,当我尝试读取或写入时,这两种用户都被拒绝许可。
编辑
我在这里添加了一个示例项目:
https://github.com/formido/react-firebaseui-web-Whosebug-question
如果我将规则设置为:
{
"rules": {
".read": "auth != null",
"44358340": { ".write": true }
}
}
...并登录,控制台会打印Timestamp written
.
如果我将规则设置为:
{
"rules": {
".read": "auth != null",
"44358340": { ".write": "auth != null" }
}
}
...并登录,控制台将打印 PERMISSION DENIED。
我知道的代码中最相关的部分是:
componentDidMount() {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
const ref = firebase.database().ref("/44358340");
if (user) {
const timestamp = firebase.database.ServerValue.TIMESTAMP;
ref.set(timestamp).then((error) => {
if (error) {
console.error(error);
}
else {
console.log('Timestamp written');
}
});
}
}
this.setState({loading: false, user});
});
}
它托管在亚马逊服务器上。我想也许我必须将 AUTH_DOMAIN
设置为 AWS 主机,但这并没有什么不同。
这是一个错误。参见 discussion starting here。
Fix here and it was deployed in Firebase 4.1.2.