This commit is contained in:
sedmedgh
2022-01-13 12:39:52 +03:30
parent ea9904acfb
commit 90687db70e
4 changed files with 28 additions and 8 deletions
+7 -5
View File
@@ -1,5 +1,6 @@
import axios from 'axios'
import router from '@/router'
import store from '@/store/store'
const domain = ""
// import themeConfig from '@/../themeConfig.js'
@@ -8,6 +9,7 @@ const noAthUrl =["/register/form",
"/auth/register",
"/pages/error-404",
"/pages/error-403",
"/register/form",
"/auth/forgot-password"]
const token = sessionStorage.getItem("accessToken") || sessionStorage.accessToken || null
const headers = {
@@ -26,8 +28,8 @@ myax.interceptors.request.use(
function (config) {
// Do something before request is sent
if (process.browser) {
if (!sessionStorage.getItem("accessToken") && !noAthUrl.includes(router.currentRoute.fullPath)) {
console.log("router req::::",router.currentRoute)
if (!sessionStorage.getItem("accessToken") && !noAthUrl.includes(store.state.route.route)) {
console.log("router req::::",store.state.route.route)
router.push('/auth/login');
}
}
@@ -64,11 +66,11 @@ myax.interceptors.response.use(
return res;
},
function ({response}) {
if (response.status === 401 && !noAthUrl.includes(router.currentRoute.fullPath)) {
console.log("router response::::",router.currentRoute)
if (response.status === 401 && !noAthUrl.includes(store.state.route.route)) {
console.log("router response::::",store.state.route.route)
router.push({path:'/auth/login'});
}
if(response.status === 403 && router.currentRoute.fullPath !== '/error-403'){
if(response.status === 403 && store.state.route.route !== '/error-403'){
console.log('403333333333333')
router.push({path:'/error-403'});
}
+4 -2
View File
@@ -1,6 +1,7 @@
import Vue from 'vue'
import Router from 'vue-router'
import 'firebase/auth'
import store from "./store/store";
Vue.use(Router)
@@ -151,16 +152,17 @@ const router = new Router({
],
})
router.afterEach(() => {
router.afterEach((to) => {
const appLoading = document.getElementById('loading-bg')
if (appLoading) {
appLoading.style.display = "none";
}
})
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
// return next();
let isLogin = sessionStorage.getItem('accessToken');
await store.commit('route/SET_ROUTE',to.path)
//console.log("to.path ==> ", to.path);
if (
to.path === "/register/form" ||
+14
View File
@@ -0,0 +1,14 @@
const state = {
route: '/register/form',
}
const mutations = {
SET_ROUTE(state, route) {
state.route = route
}
}
export default {
namespaced: true,
state,
mutations,
}
+3 -1
View File
@@ -43,6 +43,7 @@ import badadv from './badadv/badadv'
import points from './point/points'
import transaction from './transaction/transaction'
import price from './price/price'
import route from './route'
export default new Vuex.Store({
getters,
@@ -70,7 +71,8 @@ export default new Vuex.Store({
transaction:transaction,
price:price,
variantAdd:variantAdd,
advModel:advModel
advModel:advModel,
route:route,
},
strict: process.env.NODE_ENV !== 'production'
})