Describe the bug
This may be similar to https://github.com/FirebaseExtended/flutterfire/issues/185 but in my case I'm able to stream a document with an _active state_ with or without permissions. In case of no permissions the only feedback is in the debug console:
W/Firestore( 2155): (19.0.0) [Firestore]: Listen for Query(tests/test1) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
I/System.out( 2155): com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
To Reproduce
In Firestore create a tests collection with a test1 document. Set the read rules to false;
return Container(
child: StreamBuilder<DocumentSnapshot>(
stream: Firestore.instance.collection('tests').document('test1').snapshots(),
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError)
return Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.active:
return Text(snapshot.data['name']); // <-- getting this even without permissions
default:
return Container();
}
},
),
);
Expected behavior
Getting a snapshot error.
Additional context (flutter doctor -v)
[ā] Flutter (Channel stable, v1.9.1+hotfix.6, on Microsoft Windows [Version 10.0.18363.476], locale en-CA)
⢠Flutter version 1.9.1+hotfix.6 at C:\src\flutter
⢠Framework revision 68587a0916 (10 weeks ago), 2019-09-13 19:46:58 -0700
⢠Engine revision b863200c37
⢠Dart version 2.5.0
[ā] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
⢠Android SDK at C:\Users\laptop\AppData\Local\Android\sdk
⢠Android NDK location not configured (optional; useful for native profiling support)
⢠Platform android-29, build-tools 28.0.3
⢠Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
⢠Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
⢠All Android licenses accepted.
[ā] Android Studio (version 3.5)
⢠Android Studio at C:\Program Files\Android\Android Studio
⢠Flutter plugin version 41.1.2
⢠Dart plugin version 191.8593
⢠Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[ā] VS Code, 64-bit edition (version 1.40.1)
⢠VS Code at C:\Program Files\Microsoft VS Code
⢠Flutter extension version 3.6.0
[ā] Connected device (1 available)
⢠Android SDK built for x86 ⢠emulator-5554 ⢠android-x86 ⢠Android 10 (API 29) (emulator)
⢠No issues found!
Hi @galki
I believe this will be fixed in this PR
let's see if works properly when lands.
thank you
@iapicca I believe that link is for firebase_auth?
Looks like the active state value comes from some kind of cache - I'm guessing it's a Firestore thing. Really confusing because the stream isn't active but it behaves like it is. Would still be nice (necessary) to have the PERMISSION_DENIED or whatever errors thrown for obvious reasons.
I am experiencing the same error, this query should trigger PERMISSION_DENIED but never enters onError or print a log
Firestore.instance.collection('tests').snapshots().listen(_dataHandler, onError: _errorHandler);
Hi @galki
are you still experiencing the issue with the latest stable version of flutter
and the latest version of cloud_firestore?
thank you
i have same problem
Iām having the same problem too. @iapicca it looks the the PR you mentioned is for the firebause_auth package and only has changes to comments/documentation. No relation to cloud_firestore or this issue that I can see.
@iapicca yes, I'm still experiencing the same issue on the latest stable version and the latest version of cloud firestore:
[ā] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.752], locale en-CA)
[ā] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[ā] Android Studio (version 3.6)
[ā] VS Code, 64-bit edition (version 1.43.2)
[ā] Connected device (1 available)
⢠No issues found!
and
firebase_core: ^0.4.4+3
cloud_firestore: ^0.13.4+2
FYI things work fine on the latest beta channel (only on web)
Consolidating under #1223 - we'll be looking at parsing native error messages & codes and bubbling these up to the Dart layer in a consistent cross-platform format.
W/Firestore( 4970): (21.3.0) [Firestore]: Write failed at user/izvPawr0fVZ2X78xqWR6: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter ( 4970): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(Error performing setData, PERMISSION_DENIED: Missing or insufficient permissions., null)
how to solve this?
W/Firestore( 4970): (21.3.0) [Firestore]: Write failed at user/izvPawr0fVZ2X78xqWR6: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter ( 4970): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(Error performing setData, PERMISSION_DENIED: Missing or insufficient permissions., null)
how to solve this?
Same problem. Have you found a solution?
Did you check/insert the database >> rules?
EXAMPLE
match /writethenameofyourcollection/{document=**} {
allow read: if checkUserAuthEmailVerified();
}
I will try. Thanks
W/Firestore( 4970): (21.3.0) [Firestore]: Write failed at user/izvPawr0fVZ2X78xqWR6: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter ( 4970): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(Error performing setData, PERMISSION_DENIED: Missing or insufficient permissions., null)
how to solve this?Same problem. Have you found a solution?
when i run code by making another flutter project ,then it start working .
so exact reason i am not able to find.
Hi all!
I was having similar issues with firestore permissions. After fighting it for a while, I checked the rules in the console.firebase. They looked something like this:allow read, write: if false. I never paid attention to that at first, but it turned out to be the culprit of my error. So I ended up changing to something like this: allow read, write: if request.time < timestamp.date(2020, 7, 24);
That fixed my issue. I'm posting this in case someone else might've missed something small like that.
@yvonmanzi Hey man! This worked for me. I had the same error. Could you please explain to me why it works? i'm new at firebase and flutter
It works because by default permission is denied unless steps are taken to authenticate the user to allow access to the data for stored with Google, and yvonmanzi's solution changes it to allow everyone to connect to one's API, as long as the date is earlier than the one specified.
While useful for developing/testing, because it's fast/simpler than adding authentication, it should never be used in production.
Try the below rule and it will fix the error and will work just fine.
service cloud.firestore {
match /databases/{database}/documents {
// Make sure the uid of the requesting user matches name of the user
// document. The wildcard expression {userId} makes the userId variable
// available in rules.
match /users/{userId} {
allow read, update, delete: if request.auth != null && request.auth.uid == userId;
allow create: if request.auth != null;
}
}
}
https://firebase.google.com/docs/firestore/security/rules-conditions
@yvonmanzi thanks man this worked but may i know exactly how it didnt worked with default rule ?
Most helpful comment
Hi all!
I was having similar issues with firestore permissions. After fighting it for a while, I checked the rules in the console.firebase. They looked something like this:
allow read, write: if false. I never paid attention to that at first, but it turned out to be the culprit of my error. So I ended up changing to something like this:allow read, write: if request.time < timestamp.date(2020, 7, 24);That fixed my issue. I'm posting this in case someone else might've missed something small like that.