vinieth
vinieth

Reputation: 1314

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')
        }
      )
    }
  }
}

Upvotes: 1

Views: 395

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

You also have to:

import 'firebase/auth'

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

Upvotes: 1

Related Questions