feat: add admin login

This commit is contained in:
yanghao05
2025-04-16 19:55:32 +08:00
parent 8d601d456e
commit e95fc65f5f
11 changed files with 241 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import { createRouter, createWebHashHistory } from 'vue-router';
import { useAuthStore } from './stores/auth';
// Define your routes here
const routes = [
@@ -44,6 +45,12 @@ const routes = [
path: '/orders',
name: 'Orders',
component: () => import('./pages/OrderPage.vue'),
},
{
path: '/login',
name: 'Login',
component: () => import('./pages/LoginPage.vue'),
meta: { requiresAuth: false }
}
];
@@ -53,3 +60,14 @@ export const router = createRouter({
history: createWebHashHistory(),
routes
});
// Add navigation guard
router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
if (to.meta.requiresAuth !== false && !authStore.isAuthenticated) {
next('/login');
} else {
next();
}
});