login and auth

This commit is contained in:
hptangxi
2025-07-02 20:44:30 +08:00
parent 8e1de8d29f
commit 7b372de6d8
12 changed files with 113 additions and 87 deletions

View File

@@ -1,4 +1,4 @@
import { authService } from "@/services/auth";
import { useAuthService } from "@/services/auth";
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
const routes: Array<RouteRecordRaw> = [
@@ -34,8 +34,10 @@ const router = createRouter({
routes,
});
const { checkLogin } = useAuthService();
router.beforeEach((to, _from, next) => {
const loggedIn = authService.isLoggedIn();
const loggedIn = checkLogin();
if (to.path !== "/login" && !loggedIn) {
return next({ path: "/login" });
}