【发布时间】:2020-09-01 03:20:19
【问题描述】:
我试图在用户注销时将用户重定向到欢迎页面,并在用户重新登录时将用户重定向到主页。但是 this.$router.push('/') 给了我未定义的信息。
这里是代码
handleAuthStateChanged: ({ commit }) => {
auth.onAuthStateChanged(user => {
if (user) {
commit("setLogin", true);
console.log("login");
//get current user details
let userId = auth.currentUser.uid;
db.collection("users")
.doc(userId)
.get()
.then(snapshot => {
if (snapshot.exists) {
let currentUser = snapshot.data();
commit("setUser", currentUser);
console.log(currentUser);
} else {
// snapshot.data() will be undefined in this case
console.log("No such document!");
}
});
this.$router.push("/");
} else {
console.log("logout");
commit("setLogin", false);
commit("setUser", null);
this.$router.replace("/welcome");
}
});
}
【问题讨论】:
标签: firebase vue.js vuex vue-router