Firebase - Real Time Database - Client for Admin On Rest
npm install aor-firebase-clientAn admin-on-rest client for Firebase.



``sh`
npm install aor-firebase-client --save
js
// in src/App.js
import React from 'react';
import { Admin, Resource } from 'admin-on-rest';
import { RestClient } from 'aor-firebase-client';const firebaseConfig = {
apiKey: '',
authDomain: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: ''
};
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 = () => (
);
export default App;
`$3
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 isAdminThe 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`js
// in src/App.js
...
import {RestClient, AuthClient} from 'aor-firebase-client';const firebaseConfig = {
apiKey: '',
authDomain: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: ''
};
const authConfig = {
userProfilePath: 'profiles',
userAdminProp: 'superuser'
}
const App = () => (
);
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:
`js
import {RestClient, AuthClient} from 'aor-firebase-client';
import firebase from 'firebase';const firebaseConfig = {
apiKey: '',
authDomain: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: ''
};
firebase.initializeApp(firebaseConfig);
const App = () => (
);
export default App;
``This library is licensed under the MIT Licence.