feat: base 跳转前check

This commit is contained in:
caoqianming 2025-11-06 16:09:20 +08:00
parent ac5ca4ba81
commit 0658c9e5fb
1 changed files with 10 additions and 2 deletions

View File

@ -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");
}