Ad

Can't Create Global Vue Variable ( Vue.prototype.$firebase )

I submit the form in login.vue which will call submit(). Then I'm getting below error in the web console.

Uncaught TypeError: Cannot read property 'auth' of undefined

main.js

import Vue from 'vue'
import App from './App'
import router from './router'
import * as firebase from 'firebase/app'
import { firebaseConfig } from '@/firebaseConfig';

Vue.prototype.$firebase = firebase.initializeApp(firebaseConfig)
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

login.vue

const authService = {
  methods: {
    submit () {
      this.$firebase.auth().signInWithEmailAndPassword(this.login.email, this.login.pass).then(
        (user) =>{
          this.$router.replace('bm')
        }
      )
    }
  }
}
Ad

Answer

You also have to:

import 'firebase/auth'

after the firebase/app import in order to get the Firebase Auth product functionality.

Ad
source: stackoverflow.com
Ad