WIP #216. The timing is not good. After user password is confirmed, the isLoggedIn boolean is still false, and thus causing the website to stay at the login page
This commit is contained in:
@@ -19,6 +19,7 @@ import Navbar from "@/components/Navbar.vue";
|
||||
import Loading from '@/components/Loading.vue';
|
||||
import { leaveFilter, leaveConformance } from '@/module/alertModal.js';
|
||||
import PageAdminStore from '@/stores/pageAdmin.js';
|
||||
import LoginStore from "@/stores/login.js";
|
||||
|
||||
export default {
|
||||
name: 'MainContainer',
|
||||
@@ -46,6 +47,9 @@ export default {
|
||||
'shouldKeepPreviousPage',
|
||||
'activePageComputedByRoute'
|
||||
]),
|
||||
...mapState(LoginStore, [
|
||||
'isLoggedIn',
|
||||
])
|
||||
},
|
||||
methods: {
|
||||
...mapActions(PageAdminStore, [
|
||||
@@ -60,7 +64,21 @@ export default {
|
||||
const token = document.cookie.replace(/(?:(?:^|.*;\s*)luciaToken\s*\=\s*([^;]*).*$)|^.*$/, "$1");
|
||||
this.$http.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||||
},
|
||||
// Rember, Swal modal handling is called before beforeRouteUpdate
|
||||
beforeRouteEnter(to, from, next) {
|
||||
// 重新整理畫面以及第一次進入網頁時,beforeRouteEnter這個hook會被執行,然而beforeRouteUpdate不會被執行
|
||||
const loginStore = LoginStore();
|
||||
if (!loginStore.isLoggedIn) {
|
||||
next({
|
||||
path: '/login',
|
||||
query: {
|
||||
'return-to': btoa(window.location.href),
|
||||
}
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
// Remember, Swal modal handling is called before beforeRouteUpdate
|
||||
beforeRouteUpdate(to, from, next) {
|
||||
// console.log("beforeRouteUpdate", from.name, "to:", to.name);
|
||||
this.setPrevioiusPage(from.name);
|
||||
|
||||
Reference in New Issue
Block a user