import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router' import MainLayout from '@/layouts/MainLayout.vue' import { useAuthStore } from '@/stores/auth' const routes: RouteRecordRaw[] = [ { path: '/login', name: 'login', component: () => import('@/pages/LoginPage.vue'), }, { path: '/', component: MainLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'home', component: () => import('@/pages/HomePage.vue') }, { path: 'profile', name: 'profile', component: () => import('@/pages/ProfilePage.vue') }, ], }, ] const router = createRouter({ history: createWebHistory(), routes, }) // 소셜 로그인 전용 앱: 미로그인 시 보호 경로 접근 → 로그인으로 router.beforeEach((to) => { const auth = useAuthStore() if (to.meta.requiresAuth && !auth.isAuthenticated) { return { name: 'login', query: { redirect: to.fullPath } } } if (to.name === 'login' && auth.isAuthenticated) { return { name: 'home' } } }) export default router