jichoi / lms_front star
박민혁 박민혁 2024-08-22
240822 박민혁 로그인 로직 임시 수정
@81ad08491acf14b426f66669ba3fc6a8f051185a
client/views/Login.vue
--- client/views/Login.vue
+++ client/views/Login.vue
@@ -185,8 +185,13 @@
                password: this.password,
             },
          }).then(function (response) {
+
             const token = response.headers.get('Authorization');
+            const Refreshtoken = response.headers.get('RefreshToken');
+
             store.dispatch('login', token);
+            localStorage.setItem("Refreshtoken", Refreshtoken);
+
             vm.branchPage();
          }).catch(function (error) {
             alert("아이디나 비밀번호가 잘못됐습니다 !");
@@ -197,37 +202,49 @@
       branchPage() {
          const vm = this;
          const token = localStorage.getItem('token');
-         axios.post('/auth/validateToken.json', {}, {
-            headers: {
-               Authorization: token
-            }
-         }).then(response => {
-            if (response.data.status === 'success') {
-               const userInfo = response.data.userInfo;
+
+         if (token) {
+            // JWT 토큰을 '.'로 분리
+            const tokenParts = token.split('.');
+            if (tokenParts.length === 3) {
+               const payload = tokenParts[1];
+
+               const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
+
+               // Base64 디코딩 후 UTF-8로 변환
+               const jsonPayload = decodeURIComponent(
+                  Array.prototype.map.call(atob(base64), c => {
+                     return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
+                  }).join('')
+               );
+
+               const userInfo = JSON.parse(jsonPayload);
+
+               // Vuex 스토어에 사용자 정보 저장
                store.commit('setToken', token);
                store.commit('setUser', userInfo.usid);
-               store.commit('setAuthcd', userInfo.author[0].authorCode);
-               const roles = userInfo.author.map(role => role.authorCode);
+               store.commit('setUserNm', userInfo.userNm);
+               store.commit('setAuthcd', userInfo.author[0].authority);
+               const roles = userInfo.author.map(role => role.authority);
 
-               // 학생은 Main_t로 접근할 수 없음
+               console.log(userInfo);
+
+               // 역할에 따라 페이지 이동
                if (roles.includes("STUDENT")) {
                   vm.goToPage('Dashboard');
-               }
-               // 선생님은 Main으로 접근할 수 없음
-               else if (roles.includes("TEACHER")) {
+               } else if (roles.includes("TEACHER")) {
                   vm.goToPage('Board');
-               }
-               // 부모님은 Main으로 접근할 수 없음
-               else if (roles.includes("PARENT")) {
+               } else if (roles.includes("PARENT")) {
                   vm.goToPage('Main_p');
-               } 
-               else if (roles.includes("ADMIN")) {
+               } else if (roles.includes("ADMIN")) {
                   vm.goToPage('Dashboard');
                }
+            } else {
+               console.error('Invalid token structure');
             }
-         }).catch(error => {
-               console.error(error);
-            });
+         } else {
+            console.error('No token found');
+         }
       },
       closeModal() {
          this.showModal = false;
client/views/pages/AppStore.js
--- client/views/pages/AppStore.js
+++ client/views/pages/AppStore.js
@@ -9,6 +9,7 @@
         schdlId: null,
         bookId: null,
         unitId: null,
+        unitNm: null,
         LearningId: null,
         currentLearningIds: [],
         prblmTypeId: null,
@@ -23,6 +24,7 @@
         getUserInfo(state) {
             return {
                 userId: state.userId,
+                userNm: state.userNm,
                 authcd: state.authcd,
             };
         },
@@ -58,6 +60,7 @@
         clearToken(state) {
             state.token = null;
             state.userId = null;
+            state.userNm = null;
             state.authcd = null;
             state.stdId = null;
             state.schdlId = null;
@@ -68,6 +71,9 @@
         setUser(state, userId) {
             state.userId = userId;
         },
+        setUserNm(state, userNm) {
+            state.userNm = userNm;
+        },
         setAuthcd(state, authcd) {
             state.authcd = authcd;
         },
Add a comment
List