R
R
Radiss2019-09-21 16:29:43
firebase
Radiss, 2019-09-21 16:29:43

Why is the data not being added to Firebase (Realtime Database)?

There was a problem adding data to the database.
When you try to add ad - crashes error "Reference.push failed: first argument contains undefined in property 'books.ownerId"
Perhaps the reason is in Vuifire versions?
I have mouth. firebase": "^6.6.1"
"@firebase/database": {
"version": "0.5.3",
On stack overflow, found a similar question and solution (
:"I have finally discovered the source of this issue and how to fix.Some
of the confusion was caused by the fact that, since my app is still in early development it was actually loading Vuefire from CDN rather than from a local dependency.
Recently Vuefire devs have changed from 1.x to 2.x as their official stable release. That said, it would seem that in 2.x (now the stable channel) and 3.x (next pre-release candidate) releases, with the main focus shifting to Cloudstore, there are now major problems with Realtime Database implementations. After downgrading
Vuefire to version 1.4.5 (latest 1.x release) all of my original source code is once again working as expected . " ad.js

spoiler

import * as fb from 'firebase'

class Ad {
  constructor (title, description, ownerId, imageSrc = '', promo = false, id = null) {
    this.title = title
    this.description = description
    this.ownerId = ownerId
    this.imageSrc = imageSrc
    this.promo = promo
    this.id = id
  }
}

export default {
  state: {
    ads: [
      {
        title: 'First ad',
        description: 'Hello i am description',
        promo: false,
        imageSrc: '',
        id: 'vnvjn'
      },
      {
        title: 'Second ad',
        description: 'Hello i am description',
        promo: true,
        imageSrc: '',
        id: 'fvjfj'
      },
      {
        title: 'Third ad',
        description: 'Hello i am description',
        promo: true,
        imageSrc: '',
        id: 'fhdh'
      }
    ]
  },
  mutations: {
    createAd (state, payload) {
      state.ads.push(payload)
    }
  },
  actions: {
     async createAd ({commit, getters}, payload) {
     commit('clearError')
      commit('setLoading', true)

      try {
        const newAd = new Ad(
          payload.title,
          payload.description,
          getters.user.id,
          payload.imageSrc,
          payload.promo
        )

        const ad = await fb.database().ref('ads').push(newAd)

        commit('setLoading', false)
        commit('createAd', {
          ...newAd,
          id: ad.key
        })
      } catch (error) {
        commit('setError', error.message)
        commit('setLoading', false)
        throw error
     }
    }
  },
  getters: {
    ads (state) {
      return state.ads
    },
    promoAds (state) {
      return state.ads.filter(ad => {
        return ad.promo
      })
    },
    myAds (state) {
      return state.ads
    },
    adById (state) {
      return adId => {
        return state.ads.find(ad => ad.id === adId)
      }
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergeyoffkey, 2019-10-25
@radiss

Familiar course vue) in short, you don't get an owner id because the guards script for links doesn't work correctly. That is, you sort of logged in, jumped on the home, switched to newAd, and the entire user session was lost. It is easy to check up the user brought to the console. id. Accordingly, if the user is undefined, then there is no place to take the owner from. I just didn't use Guardi for links. I apologize for the broken English, I wrote in a damn crowded minibus

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question