feat: add admin login
This commit is contained in:
33
frontend/admin/src/router/index.js
Normal file
33
frontend/admin/src/router/index.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useAuthStore } from '@/stores/authStore';
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
|
||||
// ...existing code...
|
||||
|
||||
// Add login route
|
||||
const routes = [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/pages/LoginPage.vue'),
|
||||
meta: { requiresAuth: false }
|
||||
},
|
||||
// ...existing routes...
|
||||
];
|
||||
|
||||
// Add navigation guard
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const authStore = useAuthStore();
|
||||
|
||||
if (to.meta.requiresAuth !== false && !authStore.isAuthenticated) {
|
||||
next('/login');
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user