하관우 하관우 03-19
2025-03-19 하관우 2차 로그인
@cdaa6b6bb0d36c8ff72154181397030e9f8d80f0
client/resources/api/index.js
--- client/resources/api/index.js
+++ client/resources/api/index.js
@@ -17,11 +17,11 @@
 
 async function refreshAccessToken() {
     try {
-        const refreshToken = store.state.refreshToken; // 스토어에서 리프레시 토큰 가져오기
+        const refreshToken = store.state.authorization; // 스토어에서 리프레시 토큰 가져오기
         
         // 리프레시 토큰을 포함하여 재발급 요청
-        const res = await axios.post('/refresh/tknReissue.json', {
-            refreshToken: refreshToken // 리프레시 토큰 본문에 포함
+        const res = await axios.post('/refresh/tknReissue.json', {}, {
+            withCredentials: true // 쿠키를 요청에 포함시키기 위한 옵션
         });
 
         if (res.headers.authorization) {
client/views/layout/Header.vue
--- client/views/layout/Header.vue
+++ client/views/layout/Header.vue
@@ -3,7 +3,7 @@
     <header>
         <div class="header-container w1500">
             <div class="logo-wrap">
-                <router-link :to="{path : '/'}" class="logo"><img :src="logo" alt=""></router-link>
+                <router-link :to="{ path: '/' }" class="logo"><img :src="logo" alt=""></router-link>
             </div>
             <div class="nav-wrap">
                 <nav>
@@ -13,18 +13,19 @@
                         <li>회원관리</li>
                         <li>카테고리 관리</li>
                     </ul>
-                </nav>                
+                </nav>
             </div>
             <div class="auth-area">
-                <ul>
+                <ul v-if="$store.state.userId != null">
                     <li><img src="../../resources/images/icon/user-settings-line.png" alt="">
-                        <router-link :to="{path : '/MyInfo.page'}">관리자</router-link></li>
+                        <router-link :to="{ path: '/MyInfo.page' }">{{ $store.state.userNm }}</router-link>
+                    </li>
                     <li>
                         <div class="line"></div>
                     </li>
                     <li><img src="../../resources/images/icon/logout-box-line.png" alt="">
-                        <router-link :to="{path : '/Login.page'}">로그인</router-link>
-                        </li>
+                        <a href="#" @click.prevent="logout">로그아웃</a>
+                    </li>
                 </ul>
                 <a href="#" class="all-menu"><img src="../../resources/images/allmenu.png" alt=""></a>
             </div>
@@ -32,12 +33,23 @@
     </header>
 </template>
 <script>
-    export default {
+export default {
     data() {
         return {
-        // Define the image sources
-        logo: 'client/resources/images/logo.png',
+            // Define the image sources
+            logo: 'client/resources/images/logo.png',
         };
-    }
-    };
+    },
+    methods: {
+        logout() {
+            this.$store.commit('setStoreReset'); // 로그아웃 뮤테이션 호출
+            this.isUserNm = null; // 사용자 이름 초기화
+            this.$router.push({ path: '/Login.page' }); // 로그인 페이지로 리다이렉트
+        }
+    },
+    watch: {},
+    computed: {},
+    components: {},
+    mounted() { },
+};
 </script>
(파일 끝에 줄바꿈 문자 없음)
client/views/pages/AppRouter.js
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
@@ -8,9 +8,9 @@
 import NotFound from "./etc/NotFound.vue";
 
 const routes = [
-  { path: "/", name: "MainPage", component: Main },
+  { path: "/", name: "MainPage", component: Main, meta: { authorization: ['ROLE_ADMIN', 'ROLE_USER']} },
   { path: "/Login.page", name: "Login", component: Login },
-  { path: "/MyInfo.page", name: "MyInfo", component: MyInfo },
+  { path: "/MyInfo.page", name: "MyInfo", component: MyInfo, meta: { authorization: ['ROLE_ADMIN', 'ROLE_USER']} },
   { path: "/notFound.page", name: "NotFoundPage", component: NotFound },
 ];
 
@@ -25,17 +25,21 @@
 
 AppRouter.beforeEach((to, from, next) => {
   const routeExists = AppRouter.getRoutes().some(route => route.path === to.path || (route.name && route.name === to.name));
-  const authorState = store.state.roles;
+  const userId = store.state.userId;
   const { authorization } = to.meta;
 
-  // 토큰이 없을 경우
-  if (authorState == null && to.path != '/login.page') {
+  // 로그인 상태 확인
+  const isLoggedIn = userId;
+
+  // 로그인되지 않은 경우
+  if (isLoggedIn == null && to.path !== '/Login.page') {
     alert('로그인이 필요합니다.');
-    return next('/login.page');
+    return next('/Login.page'); // 로그인 페이지로 리다이렉트
   }
+  
   // 권한이 없을 경우
   if(authorization){
-    if(!authorization.includes(authorState[0].authority)){
+    if(!authorization.includes(store.state.roles[0].authority)){
       alert('접근 권한이 없습니다.');
       return next(from.path);
     }
client/views/pages/AppStore.js
--- client/views/pages/AppStore.js
+++ client/views/pages/AppStore.js
@@ -7,7 +7,7 @@
   state: {
     authorization: null,
     // refresh: null,
-    roles: [{authority: "ROLE_USER"}],
+    roles: [],
   },
   getters: {
     getAuthorization: function () {},
@@ -36,7 +36,7 @@
       // state.refresh = null;
       state.userNm = null;
       state.userId = null;
-      state.roles = [{authority: "ROLE_USER"}];
+      state.roles = [];
     },
   },
   actions: {
Add a comment
List