When developing an application on React, such a problem appeared. There is a Firebase remote database from which I need to upload data. There is a similar application on Android that works correctly without errors, and the react-application cannot connect to the firebase. I will say right away that my access rights to the database are configured as follows:

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

When I set the property values ​​to true, I get access to the database, but I don’t want to do that, since I openly access my database. But the connection code to the firebase from the js application, here I insert the config file that firebase itself gave me:

 import firebase from 'firebase'; const config = { apiKey: "***", authDomain: "***", databaseURL: "***", projectId: "***", storageBucket: "***", messagingSenderId: "***" }; firebase.initializeApp(config); export const database = firebase.database(); export const auth = firebase.auth(); 

When firebase.auth() null When I try to output data from the database, I get the following message:

permission_denied at / restaurants: Client

How can this problem be solved?

    1 answer 1

    The access rights are quite normal. That is, such a record is completely legal:

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

    This can be found here: Get Started with Database Rules , well, and see for acquaintance here, too: User Based Security .

    If on this line you get null :

     export const auth = firebase.auth(); 

    And while trying to get data from the database received a message that "the client does not have permission to access the necessary data" , it means that the authorization attempt failed. So the user is not authorized. You need to edit the config and set the correct values.

    As soon as this line is not null :

     export const auth = firebase.auth(); 

    Then the user will be authorized and the data will be available. For reference: