• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

202
Views
How to access firebase realtimedb in NUXT js

We have a realtimedb in firebase that has data as follows:

enter image description here

On our nuxt page we have the following method:

async getDb () {
      const messageRef = this.$firebase.database.ref('test')
      try {
        const snapshot = await messageRef.once('value')
        alert(snapshot.val().message)
      } catch (e) {
        alert(e)
      }
    },

That is run by this in mounted like this:

mounted () {
    this.getDb()
  },

I keep getting this error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'database')

Am I doing something wrong? I have all of the firebase config in Nuxt.config.js and suth is working fine. I also added the realtimedb to services:

 services: {
  realtimeDb: true,
  auth: {
    ssr: true,
    // it is recommended to configure either a mutation or action but you can set both
    initialize: {
      onAuthStateChangedMutation: 'ON_AUTH_STATE_CHANGED_MUTATION'
      // onAuthStateChangedAction: 'onAuthStateChangedAction'
    }
  },

How do you actually access the data from the realtimedb so I can display the test array on my page?

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using $firebase which is not included in this documentation. To grant access to your Realtime Database use the following:

$fire.database

or

$fireModule.database

Note:

If you are using nuxt/firebase version 6 use realtimeDb and database for version 7 in services of nuxt.config.js, see this link for more details.

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error