Skip to content

Instantly share code, notes, and snippets.

@SnoopSqueak
Last active April 1, 2018 18:56
Show Gist options
  • Select an option

  • Save SnoopSqueak/d2341744bbcdc7b6173e041342b3ad54 to your computer and use it in GitHub Desktop.

Select an option

Save SnoopSqueak/d2341744bbcdc7b6173e041342b3ad54 to your computer and use it in GitHub Desktop.

Selecting the Firebase app:

In my case, I would click Bloc Chat Angular, since that's the database I set up specifically for this Bloc Chat app.

Finding the database:

Click "Database" under "Develop" and scroll down to see your data.

Finding the plus sign:

If you see that warning, "Default security rules require users to be authenticated," you will have to update your database's security rules to allow updates. Go to the Rules tab. The default rules probably look like this:

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

For this project, we will update them to this:

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

If ".read" and ".write" are always true, ANYONE can read and edit your database with the API key. This is very insecure, but will work for our purposes.

Now back to the data. Here is an example of adding an object with one property:

After clicking "Add," it looks like this:

You can use the X to delete an object. Any data that object is a parent of will also be removed!

Adding an object with multiple properties:

Note that if you omit the value OR name of a property, it will not be added:

Now let's mock up some Bloc Chat data:

If you're doing the React version of Bloc Chat, the format for rooms is slightly different. Each room should be an object with a name property, more like this:

Since we're creating the rooms manually, we have to provide our own IDs. When created from code, the rooms will have a pre-generated ID.

Now for the messages:

We set the value of the message's roomId property equal to the ID of one of our rooms. I chose the Super Awesome Room, roomId3. I called my test message Message1, but like the Rooms, they will receive random names when generated from code. You can add multiple messages if you'd like:

Just don't get too carried away. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment