0

I would like to access my Firebase database from web:

Config copied from console:

  var config = {
    apiKey: "AI***********************************98",
    authDomain: "t*****.firebaseapp.com",
    databaseURL: "https://t*****.firebaseio.com",
    projectId: "t*****",
    storageBucket: "t*****.appspot.com",
    messagingSenderId: "224202513016"
  };

  firebase.initializeApp(config);

However calling:

firebase.database().ref('/calibration/temperature').once('value').then(function(snapshot) {
    console.log(snapshot);
});

Results in:

Uncaught (in promise) Error: permission_denied at /calibration/temperature: Client doesn't have permission to access the desired data.

My rules in DB:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

I've tried to use different API keys, or restrict them to specific web page - unfortunately with no luck.

AL.
  • 36,815
  • 10
  • 142
  • 281
pixel
  • 24,905
  • 36
  • 149
  • 251

1 Answers1

3

Using auth != null in a security rule will deny access to non-authenticated users.

You've called initializeApp, but unless you've subsequently called one of the signIn... methods, you won't have an authenticated user and access will be denied by the security rules.

cartant
  • 57,105
  • 17
  • 163
  • 197