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许可证的许可。