我正在做一個 React 專案,我想同時使用來自 firebase 的 Auth 和實時資料庫。我已經設法設定了身份驗證,但資料庫匯入讓我很困難。我想使用 (database().child().push() ) 方法將資料推送到資料庫,但我無法在我的 firebase 配置中呼叫 database().ref() 方法。任何人?
import { initializeApp } from "firebase/app";
import { getAuth } from 'firebase/auth'
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyD8aGnZYjhCTopgdNhuykWvmkJSHKj_h7E",
authDomain: "bonnie-d17be.firebaseapp.com",
databaseURL: "https://bonnie-d17be-default-rtdb.firebaseio.com",
projectId: "bonnie-d17be",
storageBucket: "bonnie-d17be.appspot.com",
messagingSenderId: "397471611615",
appId: "1:397471611615:web:3f6a743f4770ff8718c76a"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const authentication = getAuth(app);
export default app;
uj5u.com熱心網友回復:
Firebase 的檔案包含命名空間 (V8) 和新功能 (V9) 語法的示例。要推送新節點,請嘗試以下代碼:
// Initialize database similar to auth
import { getDatabase } from "firebase/database";
export const database = getDatabase();
import { push, child, ref } from "firebase/database";
const dbRef = ref(database)
push(child(dbRef, 'path/')).then(() => {
console.log("Data added")
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/399037.html
