Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React/Rebase/Firebase warning: Permission Denied - How do I add user authentication?

Please excuse the simplicity of my question but I can't get Rebase/Firebase to work due to permission errors (Rebase is very similar to Firebase https://github.com/tylermcginnis/re-base)

I am building a simple website as part of a React.js tutorial and I simply want to persist some state on my page. To do this, all I want is the Firebase database, without user authentication, however when I set up the database, I get permission errors so user authentication must be mandatory.

This is what I have at the top of my main.js:

var Rebase = require('re-base');
var base = Rebase.createClass('https://fishmonger-f3761.firebaseio.com/');

and then in my main app component, I added this:

componentDidMount : function() {    
    base.syncState(this.props.params.storeId + '/fishes', {
      context : this,
      state : 'fishes'
    });

I get the following warning in my console:

FIREBASE WARNING: set at /(*my custom store name*)/fishes/fish1/name failed: permission_denied

How do I add in anonymous browser-session based user authentication to disregard this error?

like image 606
Marcus Avatar asked Jun 28 '16 09:06

Marcus


1 Answers

Firebase DB default rules require authentication.

From the Get Started with Database Rules page:

By default, your database rules require Firebase Authentication and grant full read and write permissions only to authenticated users. The default rules ensure your database isn't accessible by just anyone before you get a chance to configure it.

That means that, for instance, you can give access to anyone. You just need to change the default rules of your database to look like this (again from the same documentation page):

// These rules give anyone, even people who are not users of your app,
// read and write access to your database

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

Read the other samples on the page I linked to find one that suit your needs.

EDIT

To access the rules go to your console (make sure you're logged in Google) and select "Database" in the sidebar menu, then click on the "rules" tab. The url should be something like https://console.firebase.google.com/project/<your-project>/database/rules

like image 113
U r s u s Avatar answered Sep 21 '22 10:09

U r s u s