Reputation: 37
any idea why my { auth } functions "are not functions" but my { db } functions work just fine? Example files below.
The error I get when trying to call login() method is
[Vue warn]: Error in created hook: "TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.auth.auth is not a function"
Using Vue 2 and installed firebase with npm install firebase --save.
src/firebase.js
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
const firebaseConfig = {
apiKey: 'xx',
authDomain: 'xx',
databaseURL: 'xx',
projectId: 'xx',
storageBucket: 'xx',
messagingSenderId: 'xx',
appId: 'xx',
measurementId: 'xx',
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
const auth = firebase.auth();
export { db, auth };
login.vue
import { auth } from '@/firebase';
login() {
try {
auth
.auth()
.signInWithEmailAndPassword(this.email, this.password)
.then(() => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
} catch (error) {
console.log(error);
}
},
Example code from documentation, works just fine
import { db } from '@/firebase';
var docRef = db.collection("cities").doc("SF");
docRef.get().then((doc) => {
if (doc.exists) {
console.log("Document data:", doc.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
Upvotes: 0
Views: 212
Reputation: 83068
Since you do
const auth = firebase.auth();
export { db, auth };
you should not do
login() {
try {
auth
.auth()
.signInWithEmailAndPassword(this.email, this.password)
...
but
login() {
try {
auth
.signInWithEmailAndPassword(this.email, this.password)
...
Firestore works fine because you correctly do db.collection("cities").doc("SF");
and not db.firestore().collection("cities").doc("SF");
.
Upvotes: 1