aor-firestore-client
An admin-on-rest client for Firebase Firestore.
Installation
npm install aor-firestore-client --save
yarn add aor-firestore-client
The only difference between these two is that aor-firebase-client relies on Firebase Realtime Database
This library uses Firebase Cloud Firestore
The setup is almost identical.
Usage
As a parameter of the <Admin>
component
import React from 'react';
import { Admin, Resource } from 'admin-on-rest';
import { RestClient } from 'aor-firestore-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',
path: 'blog',
public: true,
uploadFields: []
}, 'contacts']
}
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:
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
...
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.1
- Update README.md and Package.json
License
This library is licensed under the MIT Licence.