Get Error : Firestore: The caller does not have permission to execute the specified operation. But I have already signed in
Get Error : Firestore: The caller does not have permission to execute the specified operation. But I have already signed in
我遇到了这个问题并尝试使用我找到的所有解决方案进行修复,但仍然无效。我在 firebase 云 firestore 中的规则是:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write : if auth != null ;
}
}
}
并且我已经启用了匿名登录方式。
Android
android/build.gradle
:
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
android/app/build.gradle
:
compile project(':react-native-firebase')
compile project(':react-native-fbsdk')
implementation project(':react-native-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-firestore:17.1.0'
Testing.js
:
firebase.auth().signInAnonymously().then(()=>{
firebase.app().firestore().collection('Hello').doc('hello').set({
id:'fadsa'
}).catch((err)=>{
alert(err);
})
})
这是一个问题,因为您的数据库当前具有规则。请同时检查数据库、Realtime 和 Firestore。
通常,拥有完整的安全规则或 RD 或 CF 逻辑无法完全理解的任何其他规则每次都会让您遇到该错误。
> // Full security
>
> { "rules": {
> ".read": false,
> ".write": false } }
在 Firestore 中,您可以配置如下:
> service cloud.firestore { match /databases/{database}/documents {
> match /{document=**} {
> allow read: if auth != null;
> allow write: if auth != null;
> } } }
更多例子你可以看:
https://gist.github.com/codediodeio/6dbce1305b9556c2136492522e2100f6
https://firebase.google.com/docs/database/security
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
改成这个
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
更新 Firestore 控制台上的规则文件。
设置读写权限为真。
我在 Android Stuido 上的 flutter 应用程序遇到了同样的错误,当我检查规则时,我看到允许读写操作有时间限制。所以我只是延长了时间段如下:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2022, 9, 29);
}
}
}
如果您不在您的应用程序中使用身份验证并且仅使用 Firebase Firestore。所以你可以像这样简单地改变它。
改变这个
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
进入这个
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
最后不要忘记发布这些更改以保存它。
如果你通过timeStamp指定了
如果您通过 timeStamp 指定了 Firestore 规则,则只需增加持续时间。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2023, 3, 14);;
}
}
}
注意:仅供练习和使用 Firestore 数据。如果您想构建 production-level 应用,请务必安全地定义您的 Firestore 规则。
我遇到了这个问题并尝试使用我找到的所有解决方案进行修复,但仍然无效。我在 firebase 云 firestore 中的规则是:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write : if auth != null ;
}
}
}
并且我已经启用了匿名登录方式。
Android
android/build.gradle
:
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
android/app/build.gradle
:
compile project(':react-native-firebase')
compile project(':react-native-fbsdk')
implementation project(':react-native-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-firestore:17.1.0'
Testing.js
:
firebase.auth().signInAnonymously().then(()=>{
firebase.app().firestore().collection('Hello').doc('hello').set({
id:'fadsa'
}).catch((err)=>{
alert(err);
})
})
这是一个问题,因为您的数据库当前具有规则。请同时检查数据库、Realtime 和 Firestore。
通常,拥有完整的安全规则或 RD 或 CF 逻辑无法完全理解的任何其他规则每次都会让您遇到该错误。
> // Full security
>
> { "rules": {
> ".read": false,
> ".write": false } }
在 Firestore 中,您可以配置如下:
> service cloud.firestore { match /databases/{database}/documents {
> match /{document=**} {
> allow read: if auth != null;
> allow write: if auth != null;
> } } }
更多例子你可以看: https://gist.github.com/codediodeio/6dbce1305b9556c2136492522e2100f6 https://firebase.google.com/docs/database/security
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
改成这个
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
更新 Firestore 控制台上的规则文件。 设置读写权限为真。
我在 Android Stuido 上的 flutter 应用程序遇到了同样的错误,当我检查规则时,我看到允许读写操作有时间限制。所以我只是延长了时间段如下:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2022, 9, 29);
}
}
}
如果您不在您的应用程序中使用身份验证并且仅使用 Firebase Firestore。所以你可以像这样简单地改变它。
改变这个
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
进入这个
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
最后不要忘记发布这些更改以保存它。
如果你通过timeStamp指定了
如果您通过 timeStamp 指定了 Firestore 规则,则只需增加持续时间。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2023, 3, 14);;
}
}
}
注意:仅供练习和使用 Firestore 数据。如果您想构建 production-level 应用,请务必安全地定义您的 Firestore 规则。