auth.global.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { useAuthStore } from '@/stores/auth'
  2. export default defineNuxtRouteMiddleware(async (to, from) => {
  3. const { $log } = useNuxtApp()
  4. // 로그인 없이 접근 가능한 페이지 배열에 '/roulette' 추가
  5. const tokenPassPages = ['/', '/roulette','/roulette/','/auth/popupClose','auth/popupClose']
  6. //let accountValue = useAuthStore().getAccountRole.charAt(0).toUpperCase()
  7. // 1. 로그인 없이 접근 가능한 페이지 예외 허용 (이미 로그인 상태면 메인으로 이동)
  8. if (tokenPassPages.includes(to.path)) {
  9. $log.debug('로그인/비로그인 허용 페이지 이동 | ' + to.path)
  10. const accessToken = useAuthStore().getAccessToken
  11. if (accessToken && accessToken !== '' && typeof accessToken === 'string' && to.path === '/') {
  12. return navigateTo('/view/event/evtList') // 원하는 메인 페이지로
  13. }
  14. return
  15. }
  16. // 2. 토큰 체크 (모든 페이지)
  17. if (!tokenPassPages.includes(to.path)) {
  18. const accessToken = useAuthStore().getAccessToken
  19. if (!accessToken || accessToken === '' || typeof accessToken !== 'string') {
  20. $log.error('[ 페이지 접근 불가] 인증되지 않은 사용자입니다.')
  21. return navigateTo('/')
  22. }
  23. }
  24. // 3. 서비스 모드 체크
  25. // if (useAuthStore().getServiceMode === 'INACTIVE') {
  26. // if (accountValue === 'S') {
  27. // $log.debug('페이지 이동 | ' + to.path)
  28. // } else {
  29. // return navigateTo('/')
  30. // }
  31. // }else {
  32. // $log.debug('페이지 이동 | ' + to.path)
  33. // }
  34. })