Skip to content

Latest commit

 

History

History
52 lines (43 loc) · 1.81 KB

firebase.md

File metadata and controls

52 lines (43 loc) · 1.81 KB

Get Started with Firebase

We've created a quick little "API server" on Google's Firebase Platform. You can get your own API up and running within minutes too:

  1. Signup for a Firebase account
  2. Create a new project - eg. "React Native Starter App"
  3. Turn on email/password Authentication
  4. Enable the Database feature, and import the firebase-sample-data.json file found in this repo
  5. Get the Firebase project's API credentials, and add them to the respective variables in your /src/constants/firebase.js file. You can get your projects details from Firebase, by clicking on the cog icon, next to overview > 'Add Firebase to your web app'.
  6. Add the following rules to the Database
{
  "rules": {
    ".read": false,
    ".write": false,

    "meals": {
      ".read": true
    },

    "recipes": {
      ".read": true,
    	".indexOn": ["category"]
    },

    "users": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid",

        "firstName": { ".validate": "newData.isString() && newData.val().length > 0" },
        "lastName": { ".validate": "newData.isString() && newData.val().length > 0" },
        "lastLoggedIn": { ".validate": "newData.val() <= now" },
        "signedUp": { ".validate": "newData.val() <= now" },
        "role": {
          ".validate": "(root.child('users/'+auth.uid+'/role').val() === 'admin' && newData.val() === 'admin') || newData.val() === 'user'"
        }
      }
    },

    "favourites": {
    	"$uid": {
      	".read": "auth != null && auth.uid == $uid",
      	".write": "auth != null && auth.uid == $uid"
    	}
  	}
  }
}

Want to experiment even more with Firebase? Check out the Firebase Cloud Functions