diff --git a/src/router/index.js b/src/router/index.js index 07572a2..dc1c1ac 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,5 +1,6 @@ import { createRouter, createWebHistory} from 'vue-router'; import { authToken } from '@/store/index.js' +import http from "@/api/request.js"; const routes = [ { path: "/", redirect: "/login" }, { @@ -54,7 +55,7 @@ const router = createRouter({ routes, }); -router.beforeEach((to, from, next) => { +router.beforeEach(async (to, from, next) => { if (to.path === "/login") { if (authToken.access) { next("/home"); @@ -63,7 +64,14 @@ router.beforeEach((to, from, next) => { } } else { if (authToken.access) { - next(); + try{ + await http.get("/check_token/") + next(); + } catch(e){ + authToken.access = null; + authToken.refresh = null; + next("/login"); + } } else { next("/login"); }