Having trouble creating a login function for users on my page, but I keep getting the error message "Cannot read property '$router' of undefined."
The code I'm using for login in Vue is located within the Export default section.
import {fb} from "../firebase";
import router from '../router';
export default {
name: "NavBar",
components: {...},
data() {
return {
login: false,
register: false,
name: null,
email: null,
pwd: null,
};
},
methods: {
logInner(){
fb.auth().signInWithEmailAndPassword(this.email, this.pwd)
.then(function(){
this.$router.replace('users');
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
});
},
registering() {
fb.auth().createUserWithEmailAndPassword(this.email, this.pwd)
.then((user) =>{
this.$router.replace('users');
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode == "auth/weak-password") {
alert("The password is too weak.");
} else {
alert(errorMessage);
}
console.log(error);
});
}
}
};
I have attempted to use router.push and router.go without success. Any assistance would be appreciated!