简体   繁体   中英

Data not added to firebase realtime database

I have a VueJS application and a firebase project, I'm trying to access the realtime database to add data to it but it's not working and it's not logging anything. I have a firebase.js file:

import firebase from 'firebase/compat/app'
const firebaseConfig = {
  apiKey: "myapp",
  authDomain: "myapp.firebaseapp.com",
  projectId: "myapp",
  storageBucket: "myapp",
  messagingSenderId: "myapp",
  appId: "myapp"
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
export default firebaseApp;

And i have this create user method in a file called DataService.js:

import firebase from "../firebase";
import 'firebase/compat/database';
const db = firebase.database();

create(user) {
        db.ref('users' + user.login).set({
          username: user.login,
          email: user.password,
          profile_picture : false
        },(error)=>{
          if(error){
            console.log(error)
          }else{
            console.log('all good');
          }
        });
      }

In my component, I have a method called SaveUser that i'm calling in the submit

saveuser(){
        var data = {
        login: this.login,
        password: this.password,
        isvalid: false
        };
        DataService.create(data);
        },

What am I doing wrong? I'm new to firebase and I don't really know what's not working

Your firebaseConfig variable is missing a databaseURL property, which is pretty much the only key that is required for your code to be able to find the Realtime Database on the server. So add that key/value, and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM