Giter VIP home page Giter VIP logo

aor-firebase-client's Introduction

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 { PostList } from './posts';
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 trackedResources = ['posts']

const App = () => (
    <Admin restClient={RestClient(trackedResources, firebaseConfig)} >
        <Resource name="posts" list={PostList} />
    </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.

This requires a users resource relative to the root, with the user IDs as the children and an isAdmin boolean value.

app-name
+- users
   +- USERID-FROM-FIREBASE-AUTH
      +- isAdmin: true
// 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 App = () => (
    <Admin restClient={RestClient(firebaseConfig)} authClient={AuthClient}>
        <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

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.

aor-firebase-client's People

Contributors

bilalbudhani avatar grahamlyus avatar rwoverdijk avatar shrmnk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.