Reputation: 127
I am using firebase to log users in but the console complains that firebase is not defined. I am importing, firebase, I have my config set up correctly according to the docs that firebase give you, but still no luck.
import Vue from 'vue'
import App from './App.vue'
import VeeValidate from 'vee-validate';
import router from './router';
import firebase from 'firebase';
Vue.use(VeeValidate);
Vue.config.productionTip = false
// Initialize Firebase
var config = {
apiKey: "<my api key>",
authDomain: "<my auth domain>",
databaseURL: "<my database url>",
projectId: "todo-bb5d3",
storageBucket: "",
messagingSenderId: "638496899966"
};
firebase.initializeApp(config);
new Vue({
router,
render: h => h(App)
}).$mount('#app')
the file thats causing the issue:
<template>
<div class="LogIn">
<h3>Sign Up</h3>
<input type="email" v-model="email" placeholder="email" name="" value="">
<input type="passeord" v-model="password" placeholder="password" name="" value="">
<button v-on:click="signUp" type="button" name="button">Sign Up</button>
</div>
</template>
<script>
export default{
name: 'LogIn',
data: function() {
return{
email: '',
password: ''
}
},
methods: {
signUp: function(){
firebase.auth().createUserWithEmailAndPassword(this.email, this.password).then(
function(user){
alert('Your account has been created')
},
function(err) {
alert('Opps! ' + err.message)
}
)
}
}
}
</script>
Upvotes: 1
Views: 2511
Reputation: 83058
One solution is to initialize it as follows, within the created
Instance Lifecycle hook:
new Vue({
router,
render: h => h(App),
created() {
firebase.initializeApp(
{
apiKey: "...",
authDomain: "....",
databaseURL: "..."
...
}
)
}
}).$mount('#app')
Upvotes: 0
Reputation: 597
You have to import firebase in the "file that's causing the issue".
import firebase from 'firebase';
Also not a good idea to paste your api key here, even for a test app, I suggest you edit your post and redact that.
Upvotes: 2