ไคลเอนต์ผู้ดูแลระบบบนเฟอร์เบส
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 ; แพ็คเกจช่วยให้คุณจัดการกระบวนการเข้าสู่ระบบ/ออกจากระบบโดยใช้เสา authClient เสริมของส่วนประกอบ Admin (ดูเอกสารประกอบ)
มันเก็บ firebaseToken ใน localStorage ตัวเลือกการกำหนดค่าที่มีอยู่คือ:
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 หรือคุณสามารถเลือกที่จะไม่ใช้ 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