• Stars
    star
    429
  • Rank 101,271 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A firebase data provider for the react-admin framework

react-admin-firebase

NPM Version License Downloads/week Github Issues

A firebase data provider for the React-Admin framework. It maps collections from the Firebase database (Firestore) to your react-admin application. It's an npm package!


Features

  • Firestore Dataprovider (details below)
  • Firebase AuthProvider (email, password)
  • Login with: Google, Facebook, Github etc... (Example Here)
  • Forgot password button... (Example Here)
  • Firebase storage upload functionality, with upload monitoring... (Example Here)

Pull requests welcome!!

Firestore Dataprovider Features

  • Dynamic caching of resources
  • All methods implemented; (GET, POST, GET_LIST ect...)
  • Filtering, sorting etc...
  • Ability to manage sub collections through app configuration
  • Ability to use externally initialized firebaseApp instance
  • Override firestore random id by using "id" as a field in the Create part of the resource
  • Upload to the firebase storage bucket using the standard <FileInput /> field
  • Realtime updates, using ra-realtime
    • Optional watch collection array or dontwatch collection array

Get Started

yarn add react-admin-firebase firebase

or

npm install --save react-admin-firebase firebase

Demos Basic

A simple example based on the React Admin Tutorial.

Prerequisits

  • Create a posts collection in the firebase firestore database
  • Get config credentials using the dashboard

Options

import {
  FirebaseAuthProvider,
  FirebaseDataProvider,
  FirebaseRealTimeSaga
} from 'react-admin-firebase';

const config = {
  apiKey: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  authDomain: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  databaseURL: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  projectId: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  storageBucket: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  messagingSenderId: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
};

// All options are optional
const options = {
  // Use a different root document to set your resource collections, by default it uses the root collections of firestore
  rootRef: 'root-collection/some-doc' | () => 'root-collection/some-doc',
  // Your own, previously initialized firebase app instance
  app: firebaseAppInstance,
  // Enable logging of react-admin-firebase
  logging: true,
  // Resources to watch for realtime updates, will implicitly watch all resources by default, if not set.
  watch: ['posts'],
  // Resources you explicitly dont want realtime updates for
  dontwatch: ['comments'],
  // Authentication persistence, defaults to 'session', options are 'session' | 'local' | 'none'
  persistence: 'session',
  // Disable the metadata; 'createdate', 'lastupdate', 'createdby', 'updatedby'
  disableMeta: false,
  // Have custom metadata field names instead of: 'createdate', 'lastupdate', 'createdby', 'updatedby'
  renameMetaFields: {
    created_at: 'my_created_at', // default: 'createdate'
    created_by: 'my_created_by', // default: 'createdby'
    updated_at: 'my_updated_at', // default: 'lastupdate'
    updated_by: 'my_updated_by', // default: 'updatedby'
  },
  // Prevents document from getting the ID field added as a property
  dontAddIdFieldToDoc: false,
  // Adds 'deleted' meta field for non-destructive deleting functionality
  // NOTE: Hides 'deleted' records from list views unless overridden by filtering for {deleted: true} 
  softDelete: false,
  // Changes meta fields like 'createdby' and 'updatedby' to store user IDs instead of email addresses
  associateUsersById: false,
  // Casing for meta fields like 'createdby' and 'updatedby', defaults to 'lower', options are 'lower' | 'camel' | 'snake' | 'pascal' | 'kebab'
  metaFieldCasing: 'lower',
  // Instead of saving full download url for file, save just relative path and then get download url
  // when getting docs - main use case is handling multiple firebase projects (environments)
  // and moving/copying documents/storage files between them - with relativeFilePaths, download url
  // always point to project own storage
  relativeFilePaths: false, 
  // Add file name to storage path, when set to true the file name is included in the path
  useFileNamesInStorage: false,
  // Use firebase sdk queries for pagination, filtering and sorting
  lazyLoading: {
    enabled: false
  },
  // Logging of all reads performed by app (additional feature, for lazy-loading testing)
  firestoreCostsLogger: {
    enabled: false,
    localStoragePrefix // optional
  },
  // Function to transform documentData before they are written to Firestore
  transformToDb: (resourceName, documentData, documentId) => documentDataTransformed
}

const dataProvider = FirebaseDataProvider(config, options);
const authProvider = FirebaseAuthProvider(config, options);
const firebaseRealtime = FirebaseRealTimeSaga(dataProvider, options);

Data Provider

import * as React from 'react';
import { Admin, Resource } from 'react-admin';

import { PostList, PostShow, PostCreate, PostEdit } from "./posts";
import {
  FirebaseAuthProvider,
  FirebaseDataProvider,
  FirebaseRealTimeSaga
} from 'react-admin-firebase';

const config = {
  apiKey: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  authDomain: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  databaseURL: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  projectId: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  storageBucket: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
  messagingSenderId: "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
};

const options = {};

const dataProvider = FirebaseDataProvider(config, options);
...
      <Admin 
        dataProvider={dataProvider} 
      >
        <Resource name="posts" list={PostList} show={PostShow} create={PostCreate} edit={PostEdit}/>
      </Admin>
...

Auth Provider

Using the FirebaseAuthProvider you can allow authentication in the application.

const dataProvider = FirebaseDataProvider(config);
const authProvider = FirebaseAuthProvider(config);
...
      <Admin 
        dataProvider={dataProvider}
        authProvider={authProvider}
      >
...

Also checkout how to login with: Google, Facebook, Github etc... (Example Here)

And you might want a "Forgot password" button... (Example Here)

Note

To get the currently logged in user run const user = await authProvider.checkAuth(), this will return the firebase user object, or null if there is no currently logged in user.

Realtime Updates!

NOTE: Realtime updates were removed in react-admin v3.x (see marmelab/react-admin#3908). As such, react-admin-firebase v3.x also does not support Realtime Updates. However, much of the original code used for this functionality in react-admin v2.x remains - including the documentation below. For updates on the implementation of realtime please follow these issues:

Get realtime updates from the firebase server instantly on your tables, with minimal overheads, using rxjs observables!

...
import {
  FirebaseRealTimeSaga,
  FirebaseDataProvider
} from 'react-admin-firebase';
...
const dataProvider = FirebaseDataProvider(config);
const firebaseRealtime = FirebaseRealTimeSaga(dataProvider);
...
      <Admin 
        dataProvider={dataProvider} 
        customSagas={[firebaseRealtime]}
      >
...

Realtime Options

Trigger realtime on only some routes using the options object.

...
const dataProvider = FirebaseDataProvider(config);
const options = {
  watch: ['posts', 'comments'],
  dontwatch: ['users']
}
const firebaseRealtime = FirebaseRealTimeSaga(dataProvider, options);
...

Upload Progress

Monitor file upload data using custom React component which listen for following events (CustomEvent):

  • FILE_UPLOAD_WILL_START
  • FILE_UPLOAD_START
  • FILE_UPLOAD_PROGRESS
  • FILE_UPLOAD_PAUSED
  • FILE_UPLOAD_CANCELD
  • FILE_UPLOAD_COMPLETE
  • FILE_SAVED

All events have data passed in details key:

  • fileName: the file anme
  • data: percentage for FILE_UPLOAD_PROGRESS

Events are sent to HTML DOM element with id "eventMonitor". See demo implementation for example at src-demo/src/App.js;

Help Develop react-admin-firebase?

  1. git clone https://github.com/benwinding/react-admin-firebase
  2. yarn
  3. yarn start-demo

Now all local changes in the library source code can be tested immediately in the demo app.

Run tests

To run the tests, either watch for changes or just run all tests.

  • yarn test-watch
  • yarn test

paypal

More Repositories

1

quill-html-edit-button

Quill.js Module which allows you to quickly view/edit the HTML in the editor
TypeScript
126
star
2

react-admin-import-csv

A csv file import button for react-admin
TypeScript
119
star
3

quill-image-compress

A Quill rich text editor Module which compresses images uploaded to the editor
TypeScript
100
star
4

ngext

Better routing for Angular
TypeScript
82
star
5

react-admin-firebase-demo

Demo project for the react-admin-firebase npm package
JavaScript
46
star
6

command-pal

The hackable command palette for the web, inspired by Visual Studio Code.
HTML
41
star
7

newsit

Chrome Extension for Hacker News and Reddit Links
TypeScript
21
star
8

example-jest-firestore-triggers

An example of using jest to test firestore triggers
JavaScript
19
star
9

pdfstamp

A cli tool to stamp PDF's, using (ImageMagick and pdftk)
JavaScript
19
star
10

vuex-trace

Log actions & mutations in vuex! 🚀
JavaScript
12
star
11

wealth-visualizer

Wealth Visualizer
Vue
11
star
12

vuetify-datatable-extended

An extension of vuetify-datatable to make filters a bit easier
Vue
10
star
13

ngx-filemanager

File manager for Angular
TypeScript
8
star
14

dokku-pages

Simple static sites on Dokku!
JavaScript
8
star
15

react-admin-firebase-demo-typescript

Demo project for the react-admin-firebase npm package
TypeScript
8
star
16

scrape-reduce

A simple way to scrape websites
TypeScript
7
star
17

localnotes.page

A simple website to write notes, stored in browser
HTML
3
star
18

frank-the-collie

Frank the Collie
Svelte
3
star
19

Meme-Bot-Messenger-Client

A meme responding bot for facebook messenger
JavaScript
3
star
20

quill-image-rotate-module

A module for Quill rich text editor to allow images to be rotated.
JavaScript
3
star
21

ngx-auto-table

A simple to use data table for Angular
TypeScript
3
star
22

twingex

A simple export format for Twine text adventure games
HTML
2
star
23

jira-to-github

Migrate JIRA issues to Github
TypeScript
2
star
24

zoomore

Zoom pictures and turn them into gifs!!
Dart
2
star
25

benw-blog

Stylus
1
star
26

benw-portal

My website portal!
HTML
1
star
27

mat-reduce

Angular Material is verbose, here's a wrapper library to reduce that!
TypeScript
1
star
28

pat.dog

JavaScript
1
star
29

gatsby-starter-netlify-cms

JavaScript
1
star
30

doughculator

A calculator for Dough!
TypeScript
1
star
31

cloud-html2pdf

A small node server to convert HTML documents to PDF
HTML
1
star
32

benwinding

1
star
33

ycomments-landingpage

CSS
1
star
34

lenny.homes

A website for my homie Lenny!
TypeScript
1
star
35

newsit-landingpage

HTML
1
star
36

myuni-dl

Command-line tool to download all files from a MyUni course
Python
1
star
37

mat-firebase-upload

An easy to use upload dropzone for Angular/Firebase.
TypeScript
1
star
38

firecache

Client-side state-management using Firebase
TypeScript
1
star
39

LEDMatrix64-Arduino

Based on "tomaskovacik/arduino" but altered for a 64x32 pixel LED display
Objective-C
1
star