const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', component: Home },
{ path: '/login', component: Login },
{
path: '/admin',
component: Admin,
meta: { requiresAuth: true }
}
]
})
router.beforeEach((to, from, next) => {
const authStore = useAuthStore()
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
console.warn('⛔ Access Denied: User not authenticated.')
next('/login')
} else {
next()