import { useAuthStore } from '@/stores/auth' export default defineNuxtRouteMiddleware(async (to, from) => { const { $log } = useNuxtApp() // 로그인 없이 접근 가능한 페이지 배열에 '/roulette' 추가 const tokenPassPages = [ '/', '/roulette', '/auth' ] //let accountValue = useAuthStore().getAccountRole.charAt(0).toUpperCase() // 1. 로그인 없이 접근 가능한 페이지 예외 허용 (이미 로그인 상태면 메인으로 이동) if (tokenPassPages.includes(to.path)) { $log.debug('로그인/비로그인 허용 페이지 이동 | ' + to.path) const accessToken = useAuthStore().getAccessToken if (accessToken && accessToken !== '' && typeof accessToken === 'string' && to.path === '/') { return navigateTo('/view/event/evtList') // 원하는 메인 페이지로 } return } // 2. 토큰 체크 (모든 페이지) if (!tokenPassPages.includes(to.path) && !tokenPassPages.some(path => path !== '/' && to.path.startsWith(path + '/'))) { const accessToken = useAuthStore().getAccessToken if (!accessToken || accessToken === '' || typeof accessToken !== 'string') { $log.error('[ 페이지 접근 불가] 인증되지 않은 사용자입니다.') return navigateTo('/') } } // 3. 서비스 모드 체크 // if (useAuthStore().getServiceMode === 'INACTIVE') { // if (accountValue === 'S') { // $log.debug('페이지 이동 | ' + to.path) // } else { // return navigateTo('/') // } // }else { // $log.debug('페이지 이동 | ' + to.path) // } })