Firebase client for Admin on Rest
Clone or download
sidferreira 0.4.0 (#42)
* Starts the v0.4.0 refactor

* Work In Progress - Basic Behavior working on demo

* Small tweak

* Auth is working

* Image Upload is back up

* Keep params in the same way as before
Latest commit 05a411b Oct 3, 2018
Permalink
Failed to load latest commit information.
.circleci Adds initial tests + fix bug Jul 12, 2017
demo 0.4.0 (#42) Oct 3, 2018
src 0.4.0 (#42) Oct 3, 2018
tests 0.4.0 (#42) Oct 3, 2018
.babelrc 0.4.0 (#42) Oct 3, 2018
.editorconfig 0.4.0 (#42) Oct 3, 2018
.eslintrc 0.4.0 (#42) Oct 3, 2018
.gitignore Update dependencies and prepares to `react-admin` Apr 22, 2018
.npmignore ignores Jul 12, 2017
LICENSE Initial commit Jun 25, 2017
README.md 0.2.0-alpha.5 Feb 27, 2018
_config.yml Set theme jekyll-theme-minimal Jul 12, 2017
package.json 0.4.0 (#42) Oct 3, 2018
yarn.lock 0.4.0 (#42) Oct 3, 2018

README.md

aor-firebase-client

An admin-on-rest client for Firebase.

npm version CircleCI CircleCI

Installation

npm install aor-firebase-client --save

Usage

As a parameter of the <Admin> component

// in src/App.js
import React from 'react';
import { Admin, Resource } from 'admin-on-rest';
import { RestClient } from 'aor-firebase-client';

const firebaseConfig = {
    apiKey: '<your-api-key>',
    authDomain: '<your-auth-domain>',
    databaseURL: '<your-database-url>',
    storageBucket: '<your-storage-bucket>',
    messagingSenderId: '<your-sender-id>'
};

const clientOptions = {
  timestampFieldNames: {
    createdAt: 'createdAt',
    updatedAt: 'updatedAt'
  },
  trackedResources: [{
    name: 'posts', // The name reference to be used in all other places in AOR
    path: 'blog', // The path in the database. If missing will use the name
    public: true,
    uploadFields: [] // The string name of the field
  }, 'contacts'] // A single string assumes path and name as equal, non private and without upload fields
}

const App = () => (
    <Admin restClient={RestClient(trackedResources, clientOptions)} >
        <Resource name="posts" list={PostList} />
        <Resource name="contacts" list={ContactList} />
    </Admin>
);

export default App;

Auth Client

The package lets you manage the login/logout process implementing an optional authClient prop of the Admin component (see documentation).
It stores a firebaseToken in localStorage. The configuration options available are:

  • userProfilePath: The database path to user profiles. Defaults to /users/. Mind the slashes.

  • userAdminProp: The database key to point if a user has admin powers. Defaults to isAdmin

The final path is: {userProfilePath}/{uid}/{userAdminProp}

  • localStorageTokenName: Local storage identifier to hold the firebase client token, defaults to aorFirebaseClientToken

  • handleAuthStateChange: A way to override the auth process

// in src/App.js
...
import {RestClient, AuthClient} from 'aor-firebase-client';

const firebaseConfig = {
    apiKey: '<your-api-key>',
    authDomain: '<your-auth-domain>',
    databaseURL: '<your-database-url>',
    storageBucket: '<your-storage-bucket>',
    messagingSenderId: '<your-sender-id>'
};

const authConfig = {
    userProfilePath: 'profiles',
    userAdminProp: 'superuser'
}

const App = () => (
    <Admin restClient={RestClient(firebaseConfig)} authClient={AuthClient(authConfig)}>
        <Resource name="posts" list={PostList} />
    </Admin>
);

export default App;

Note: AuthClient does require using the RestClient in order to initialize firebase. Alternatively, you can opt to not use the RestClient and initialize firebase yourself like this:

import {RestClient, AuthClient} from 'aor-firebase-client';
import firebase from 'firebase';

const firebaseConfig = {
    apiKey: '<your-api-key>',
    authDomain: '<your-auth-domain>',
    databaseURL: '<your-database-url>',
    storageBucket: '<your-storage-bucket>',
    messagingSenderId: '<your-sender-id>'
};

firebase.initializeApp(firebaseConfig);

const App = () => (
    <Admin authClient={AuthClient()}>
        <Resource name="posts" list={PostList} />
    </Admin>
);

export default App;

Changelog

v0.0.10

  • Documentation fix for authClient #17
  • Handle empty collections #18
  • Build lib on prepare #19
  • Thanks to @grahamlyus who worked a LOT this month to make this release possible! Kudos!

v0.0.9

  • Fixes

v0.0.8

  • Fix it saving on the wrong path #7
  • Fix README links

v0.0.7

  • Typos, tests and fixes #6

v0.0.6

  • README Fixes #4

v0.0.4

  • CI configured

v0.0.3

  • Fixed Auth Client configuration #2
  • Added timestamps #3
  • Initial unit testing / CI

v0.0.1

  • Initial commit, lots of to dos

License

This library is licensed under the MIT Licence.