title: Permission denied when reading from database
body: <p>I have a problem reading data from a firebase database.</p>
  
  <p>The code below belongs to a function attached to a [FlatButton]:</p>
  
  <pre><code>void newEntry(){
      print(_database.reference().child('todo').equalTo('Dan').once().then((value){
        print(value.key);
      }));
    }
  </code></pre>
  
  <p>Whenever I run this piece of code I get this error:</p>
  
  <pre><code>I/flutter (29847): Instance of 'Future&lt;dynamic&gt;'
  D/NetworkSecurityConfig(29847): No Network Security Config specified, using platform default
  W/SyncTree(29847): Listen at /todo failed: DatabaseError: Permission denied
  E/flutter (29847): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Instance of 'DatabaseError'
  E/flutter (29847): #0      Query.once (package:firebase_database/src/query.dart:90:41)
  E/flutter (29847): &lt;asynchronous suspension&gt;
  E/flutter (29847): #1      _MyAppState.newEntry (package:database_project/main.dart:94:62)
  E/flutter (29847): #2      _MyAppState._buildButton.&lt;anonymous closure&gt; (package:database_project/main.dart:88:9)
  E/flutter (29847): #3      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511:14)
  E/flutter (29847): #4      _InkResponseState.build.&lt;anonymous closure&gt; (package:flutter/src/material/ink_well.dart:566:30)
  E/flutter (29847): #5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
  E/flutter (29847): #6      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9)
  E/flutter (29847): #7      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:177:9)
  E/flutter (29847): #8      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:436:9)
  E/flutter (29847): #9      PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
  E/flutter (29847): #10     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
  E/flutter (29847): #11     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:221:19)
  E/flutter (29847): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22)chEvent (package:flutter/src/gestures/binding.dart:199:22)                         ePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
  E/flutter (29847): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)ePointerEvent (package:flutter/src/gestures/binding.dart:156:7)                    ePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
  E/flutter (29847): #14     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
  E/flutter (29847): #15     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
  E/flutter (29847): #16     _rootRunUnary (dart:async/zone.dart:1136:13)
  E/flutter (29847): #17     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
  E/flutter (29847): #18     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)                                                                                   ity]
  E/flutter (29847): #19     _invoke1 (dart:ui/hooks.dart:233:10)
  E/flutter (29847): #20     _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5)   w{8084b2a VFE...... .F...... 0,0-1440,2872} of ViewRootImpl@b8c6359[MainActivity]
  E/flutter (29847):                                                                 t/com.example.database_project.MainActivity@8084b2a@0[29847])/@0xeeafd1b io.flutter.view.FlutterView{8084b2a VFE.D/ViewRootImpl@b8c6359[MainActivity](29847): MSG_WINDOW_FOCUS_CHANGED 0 1
  D/InputMethodManager(29847): prepareNavigationBarInfo() DecorView@48d0f7a[MainActivew{8084b2a VFE...... .F...... 0,0-1440,2872}ity]
  D/InputMethodManager(29847): getNavigationBarColor() -855310D/SurfaceView(29847): onWindowVisibilityChanged(8) false io.flutter.view.FlutterView{8084b2a VFE...... .F...... 0,0-1440,2872} of ViewRootImpl@b8c6359[MainActivity]D/SurfaceView(29847): show() Surface(name=SurfaceView - com.example.database_project/com.example.database_project.MainActivity@8084b2a@0[29847])/@0xeeafd1b io.flutter.view.FlutterView{8084b2a VFE...... .F...... 0,0-1440,2872}D/SurfaceView(29847): surfaceDestroyed callback.size 1 #2 io.flutter.view.FlutterView{8084b2a VFE...... .F...... 0,0-1440,2872}W/libEGL  (29847): EGLNativeWindowType 0x7af3edd010 disconnect failed
  D/SurfaceView(29847): destroy() Surface(name=SurfaceView - com.example.database_project/com.example.database_project.MainActivity@8084b2a@0[29847])/@0xeeafd1b io.flutter.view.FlutterView{8084b2a VFE...... .F...... 0,0-1440,2872}W/libEGL  (29847): EGLNativeWindowType 0x7b02e2a010 disconnect failedD/OpenGLRenderer(29847): eglDestroySurface = 0x7af3f13680, 0x7b02e2a000D/ViewRootImpl@b8c6359[MainActivity](29847): Relayout returned: old=[0,0][1440,3040] new=[0,0][1440,3040] result=0x5 surface={valid=false 0} changed=trueD/ViewRootImpl@b8c6359[MainActivity](29847): setWindowStopped(true) old=false
  D/SurfaceView(29847): windowStopped(true) false io.flutter.view.FlutterView{8084b2a VFE...... .F...... 0,0-1440,2872} of ViewRootImpl@b8c6359[MainActivity]
  D/ViewRootImpl@b8c6359[MainActivity](29847): Surface release. android.view.WindowManagerGlobal.setStoppedState:669 android.app.Activity.performStop:7647 android.app.ActivityThread.callActivityOnStop:4372 android.app.ActivityThread.performStopActivityInner:4350 android.app.ActivityThread.handleStopActivity:4425 android.app.servertransaction.StopActivityItem.execute:41 android.app.servertransaction.TransactionExecutor.executeLifecycleState:145 android.app.servertransaction.TransactionExecutor.execute:70
  D/InputTransport(29847): Input channel destroyed: fd=100
  I/FirebaseAuth(29847): [FirebaseAuth:] Loading module via FirebaseOptions.I/FirebaseAuth(29847): [FirebaseAuth:] Preparing to create service connection to gms implementation
  </code></pre>
  
  <p>As for the path of the database is <code>todo/userId/Dan</code> <a href="https://ibb.co/mFk7Cpp" rel="nofollow noreferrer">Database</a>.</p>
  
  <p>EDIT: Forgot to mention that I updated my security rules as following:</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
      match /{document=**} {
        allow read, write: if request.auth != null;
      }
    }
  }
  </code></pre>
  
  <blockquote>
    <p>EDIT</p>
  </blockquote>
  
  <p>As per @Andrey Ilyunin comment I've authenticated my application to an user and applied the same security rules. I still get the same exception, i.e:</p>
  
  <pre><code>D/NetworkSecurityConfig( 4123): No Network Security Config specified, using platform default
  W/SyncTree( 4123): Listen at /todo failed: DatabaseError: Permission denied
  E/flutter ( 4123): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Instance of 'DatabaseError'
  E/flutter ( 4123): null
  E/flutter ( 4123): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Instance of 'DatabaseError'
  E/flutter ( 4123): null
  </code></pre>