feat: add admin login
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user