问题
I've got the error
'W/SyncTree(31625): Listen at /address failed: DatabaseError: Permission denied'
while sending a request to firebase with an anonymous firebase user and without fancy firebase database rules :) . ..and i want to find out what causes this message.
EDIT: error is the same with an existing user, means user signIn seems to work but accessing database not.
What i've done so far:
- Set up firebase (including adding google_service.json, dependencies in pubspec.yaml) - works so far
creating login as follows (like in example from google link):
Future<String> _testSignInAnonymously() async { final FirebaseUser user = await _auth.signInAnonymously(); assert(user != null); assert(user.isAnonymous); assert(!user.isEmailVerified); assert(await user.getIdToken() != null); assert(user.providerData.length == 1); assert(user.providerData[0].providerId == 'firebase'); assert(user.providerData[0].uid != null); assert(user.providerData[0].displayName != null); assert(user.providerData[0].photoUrl == null); assert(user.providerData[0].email != null); final FirebaseUser currentUser = await _auth.currentUser(); print(currentUser.uid); print(currentUser.isAnonymous); assert(user.uid == currentUser.uid); return 'signInAnonymously succeeded: $user'; }
the print statement provides a userId (and this id is also in firebase auth section) --> seems to me that i've got an logged in user
implement kind of initialization like in the google example (link):
Future<void> main() async { final FirebaseApp app = await FirebaseApp.configure( name: 'mydbName', options: const FirebaseOptions( googleAppID: 'myAppId', apiKey: 'myApiKey', databaseURL: 'myUrl', ), ); runApp(new MyApp(app)); }
on another stateful widget in state i try to request some firebase data:
void initState() { final FirebaseDatabase database = new FirebaseDatabase(app: widget.app); database.reference().child('address').once().then((DataSnapshot snapshot) { print('Connected to database and read ${snapshot.value}'); }); super.initState(); }
i've removed all rules in firebase except:
".read": "auth != null", ".write": "auth != null",
i use an SHA-1 certificate/fingerprint in my
firebase android app
- i use the same firebase database with an
firebase ios app
without any problem while using anonymous users
What i need:
I need some hint how to find out if there's any problem with that initialization code or with the user login or something else
回答1:
It seems the database is not correctly addressed in FirebaseApp.configure(
FirebaseDatabase.instance.reference().child(...)
would use the default database of the project configured in google-services.json
来源:https://stackoverflow.com/questions/52203529/what-causes-permission-denied-message-with-firebase-and-flutter