I am facing an issue while trying to push my data to the Firebase real-time database in Next.js/React using the modular version. The error I encounter is as follows:
TypeError: ref._location is undefined
Below is the code snippet of what I have been attempting:
import firebase from "firebase/compat/app";
import { app } from '../../firebase_config';
import { db } from '../../firebase_config';
import { getDatabase, set, update } from "firebase/database";
import { ref } from 'firebase/storage';
import {auth} from '../../firebase_config'
import { getAuth, onAuthStateChanged } from "firebase/auth";
onAuthStateChanged(auth, async (user) => {
if (user) {
const uid = user.uid;
// pushing data to the Firebase table
const db = getDatabase(app);
const dbRef = ref(db, 'users/' + uid);
update(dbRef, {displayName: "Firebase9_IsCool"}).then(() => {
console.log("Data updated");
}).catch((e) => {
console.log(e);
})
console.log('Successfully pushed to Firebase');
}
});