0

I'm trying to read data in a Realtime Database in Firebase but I get an error:

Client doesn't have permission to access the desired data.

This is the code for reading:

final ref = FirebaseDatabase.instance.ref();
    final snapshot = await ref.child('data').get();
    if (snapshot.exists) {
      print(snapshot.value);
    } else {
      print('No data available.');
    }

this is the database structure:

structure

And this is the security rules:

{
    "rules": {    
        ".read": true,
        ".write": true
    }
}

I also updated the google-services.json file. Error in Android:

W/PersistentConnection( 8311): pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt to reconnect. Reason: The database lives in a different region. Please change your database URL to https://xxxx-rtdb.europe-west1.firebasedatabase.app

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
blacky99
  • 115
  • 1
  • 12
  • Can you show the complete error message you get, as it usually include the exact path and operation that are causing it right before the "Client doesn't have permission to access the desired data." message that you included? – Frank van Puffelen Dec 19 '22 at 20:16
  • Please edit your question and add the information Frank asked for, and please also respond using @. – Alex Mamo Dec 20 '22 at 08:17
  • I don't understand why but trying to deploy on ios I don't get any errors in the debug console anymore (but it still doesn't work). Trying to deploy to android I got an error which I attached in the question @AlexMamo – blacky99 Dec 20 '22 at 16:46
  • I'll check on ios shortly – blacky99 Dec 20 '22 at 16:52
  • In ios after updating GoogleService-Info.plist it's working! – blacky99 Dec 20 '22 at 17:56

1 Answers1

0

You're getting the following error:

Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL to https://xxxx-rtdb.europe-west1.firebasedatabase.app

Because you're creating an instance of FirebaseDatabase using the default location. When you aren't explicitly setting the location, the default one is "us-central1". So as the error message says, you have to set the location to be "europe-west1", rather than the US.

Regarding Firebase Realtime Database locations, please check the official documentation:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193