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は、FireBaseを初期化するためにRESTClientを使用する必要があります。または、RESTCLIENTを使用しないことを選択し、このように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ライセンスに基づいてライセンスされています。