Skip to content

1. Firebase Project Setup

Faisal Ramdan edited this page May 28, 2021 · 4 revisions

Create Firebase Project

  • You need to create a Firebase project for the first time. You may use existing Firebase project.

  • Go to Firebsae console, https://console.firebase.google.com/

    • click (+) Add project menu.
    • enter project name. You can enter any name. ex) fireflutter-test
    • click Continue button.
    • disable Enable Google Analytics for this project. You can eanble it if you can handle it.
      • click Continue button.
    • new Firebase project will be created for you in a few seconds.
      • Tehn, click Continue button.
  • Read Understand Firebase projects for details.

Enable Firestore

  • Go to Cloud Firestore menu.
  • Click Create Database.
  • Choose Start in production mode.
  • Click Next.
  • Choose nearest Cloud Firestore location.
    • To know the right location, click Learn more.
  • Click Enable.

Install Firestore Security Rules

Firestore needs security rules to secure its data.

  • Copy the rules from fireflutter firestore security rules
  • Go Cloud Firestore => Rules => Edit rules and delete all the rules there and paste the fireflutter firestore security rules.
  • Click publish.

Security Rules Testing

This is optional.

If you wish to test Firestore security rules, you may do so with the following command.

Run Firebase emualtor first.

$ firebase emulators:start --only firestore

run the tests.

$ npm run test
$ npm run test:basic
$ npm run test:user
$ npm run test:admin
$ npm run test:category
$ npm run test:post
$ npm run test:comment
$ npm run test:vote
$ npm run test:user.token
$ npm run test:chat

Update Firestore Index

There are three ways of updating Firestore security rules.

  1. Creating the index on Firebase console.
  2. Deploying the index from FireFluter Firebase.
  3. By clicking the URL on debug console while your are developing the app. And this may be the easiest from the other two.
  • Create complex indexes like below.
    • Go Cloud Firestore => Indexes => Composite => + Create Index
Collection ID Fields indexed Query scope Status
posts category Ascending createdAt Descending Collection Enabled
posts category Ascending uid Ascending createdAt Descending Collection Enabled

Example of adding Firestore indexes) Firestore Index

Enable Storage

  • Enable Stroage in the project menu on firebase console.
  • And add the following security rules.
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read: if true;
      allow create: if request.auth != null;
      allow delete: if resource.metadata.uid == request.auth.uid;
    }
  }
}

Firebase Email/Password Login

Clone this wiki locally