1. Requirements:
there are two logins (merchant login page, user login page):
-1-first login merchant
-2-login user
-3-after the merchant logs in for the first time, there is no need to log in again, jump directly to the user page user login
2. There is already a code
for the merchant to log in for the first time. After the request for http, is successful, save the value to vuex
this.axios.post("/api/user/login.do", qs.stringify({
username: this.username,
password: this.password,
type: "pos_seller"
})).then(response => {
if (response.data.result === "success") {
// this.$router.push("/login")
let user = {};
user.user_name = response.data.user.displayName;
user.user_token = response.data.user.userId;
this.setUser(user);//vuex
}
}).catch(error => {
console.log("error====>" + error)
})
inside router:
router.beforeEach((to, from, next) => {
// console.log(store.state.currentUser.UserToken); //
if (to.meta.requireAuth) {
let token = store.state.currentUser.UserToken;
if (token) {
if (to.path === "/login") {
console.log(to)
next("/login")
}
}
else {
next({
path: "/sellerlogin",
query: {redirect: to.fullPath}
})
}
}
else {
next();
}
})
3. Result:
Click the merchant to log in, and it will not be able to achieve the desired effect (there is a value in localStorage, which automatically jumps to the user login page)
4. Question
-1-what"s wrong with the above code
-2-is login blocking done in general? I read on the Internet that axios interception is also needed, that is to say, front-end route interception + axios interception?