G
G
gallantalex2017-05-03 01:58:06
JavaScript
gallantalex, 2017-05-03 01:58:06

How to connect to firebase?

When developing an application in React, there was such a problem. I have a Firebase Remote Database that I need to upload data from. There is a similar android app that works correctly without errors, but the react app can't connect to 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 properties to true, I get access to the database, but I don't want to do this, since I open free access to my database.
And here is the code for connecting to firebase from the js application, here I insert the config that firebase 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();

Firebase.auth() returns null
When I try to retrieve data from the database, I get this message:
permission_denied at /restaurants: Client doesn't have permission to access the desired data
How can I solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2017-05-03
@gallantalex

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

means that only an authorized user can read and write, that is, you first need to register it, you can use mail and password, or social networks
, you can also use the simulator for verification (click the button in the firebase console)
https://firebase.google.com/docs/auth /web/password-auth
PS In general, the system of rights in firebase is very flexible, right now you have any authorized user has the right to read and write to any place about the database, even completely overwrite
PS and you are sure that you really need firebase

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question