aor firebase client
1.0.0
firebase的管理員客戶端。
npm install aor-firebase-client --save<Admin>組件的參數 // 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 ;該軟件包允許您管理登錄/註銷過程,以實現Admin組件的可選authClient驗證配置(請參閱文檔)。
它在localStorage中存儲firebaseToken 。可用的配置選項是:
userProfilePath :用戶配置文件的數據庫路徑。默認為/users/ 。介意斜線。
userAdminProp :指向用戶是否具有管理權的數據庫密鑰。默認為isAdmin
最終路徑是: {userProfilePath}/{uid}/{userAdminProp}
localStorageTokenName :持有firebase客戶端令牌的本地存儲標識符,默認為aorFirebaseClientToken
handleAuthStateChange :覆蓋驗證過程的一種方法
// 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 ;注意: Authclient確實需要使用RESTCLIENT才能初始化Firebase。另外,您可以選擇不使用RESTCLCLIENT並像這樣初始化Firebase:
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 ; 該圖書館已獲得MIT許可證的許可。