

250423 김혜민 세션로그인에러 수정
@7d80ac42be9740fc3b228ab226f4a634cce259b4
--- client/resources/api/index.js
+++ client/resources/api/index.js
... | ... | @@ -69,8 +69,6 @@ |
69 | 69 |
sessionStorage.setItem("redirect", redirect); |
70 | 70 |
alert('세션이 종료 되었습니다.\n로그인을 새로 해주세요.'); |
71 | 71 |
store.commit("setStoreReset"); |
72 |
- //refresh 쿠키 삭제 |
|
73 |
- document.cookie = "refresh=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; |
|
74 | 72 |
window.location = '/login.page'; |
75 | 73 |
return Promise.reject(refreshError); |
76 | 74 |
} |
--- client/views/index.js
+++ client/views/index.js
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 |
async function initVueApp() { |
23 | 23 |
const savedLoginMode = localStorage.getItem("loginMode"); |
24 | 24 |
if (savedLoginMode) { |
25 |
- store.commit("setLoginMode", savedLoginMode); |
|
25 |
+ Store.commit("setLoginMode", savedLoginMode); |
|
26 | 26 |
} |
27 | 27 |
|
28 | 28 |
const router = await createAppRouter() |
--- client/views/pages/App.vue
+++ client/views/pages/App.vue
... | ... | @@ -29,11 +29,6 @@ |
29 | 29 |
path: "", |
30 | 30 |
}; |
31 | 31 |
}, |
32 |
- created() { |
|
33 |
- const loginMode = localStorage.getItem("loginMode"); |
|
34 |
- if (loginMode) { |
|
35 |
- this.$store.commit("setLoginMode", loginMode); |
|
36 |
- }}, |
|
37 | 32 |
methods: {}, |
38 | 33 |
watch: { |
39 | 34 |
$route(to, from) { |
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
... | ... | @@ -135,6 +135,7 @@ |
135 | 135 |
// 권한 검증 |
136 | 136 |
function isValidRole() { |
137 | 137 |
const roles = store.state.roles; |
138 |
+ console.log('권한확인',roles); |
|
138 | 139 |
if (!Array.isArray(roles)) { |
139 | 140 |
store.commit("setStoreReset"); |
140 | 141 |
return false; |
... | ... | @@ -176,18 +177,11 @@ |
176 | 177 |
const isLogin = loginMode === 'J' ? store.state.authorization : store.state.mbrId; |
177 | 178 |
if (!isLogin && to.path !== filters.ctxPath('/login.page')) { |
178 | 179 |
next({ path: filters.ctxPath("/login.page") }); |
179 |
- return; |
|
180 |
+ return; |
|
180 | 181 |
} |
181 | 182 |
|
182 | 183 |
// 접근 제어 확인 |
183 |
- let accesCheck = false; |
|
184 |
- if (loginMode === 'J') { |
|
185 |
- // JWT 방식 접근 제어 |
|
186 |
- accesCheck = await accessUrl(to.path); |
|
187 |
- } else if (loginMode === 'S') { |
|
188 |
- // 세션 방식 접근 제어 (세션이 유효한지 확인) |
|
189 |
- accesCheck = store.state.mbrId != null; |
|
190 |
- } |
|
184 |
+ const accesCheck = await accessUrl(to.path); |
|
191 | 185 |
console.log('accesCheck', accesCheck); |
192 | 186 |
const roleCheck = isValidRole(); |
193 | 187 |
if (!accesCheck || !roleCheck) { |
--- client/views/pages/AppStore.js
+++ client/views/pages/AppStore.js
... | ... | @@ -3,10 +3,13 @@ |
3 | 3 |
import { logOutProc } from "../../resources/api/logOut" |
4 | 4 |
|
5 | 5 |
export default createStore({ |
6 |
- plugins: [createPersistedState()], |
|
6 |
+ plugins: [createPersistedState({ |
|
7 |
+ paths: ['loginMode', 'authorization', 'mbrId', 'mbrNm', 'roles', 'contextPath'] |
|
8 |
+ })], |
|
7 | 9 |
state: { |
8 | 10 |
authorization: null, |
9 | 11 |
// refresh: null, |
12 |
+ loginMode: 'J', |
|
10 | 13 |
userType: "portal", |
11 | 14 |
menu: null, |
12 | 15 |
path: null, |
... | ... | @@ -19,6 +22,7 @@ |
19 | 22 |
// getRefresh: function () {}, |
20 | 23 |
getMbrNm: function () {}, |
21 | 24 |
getRoles: function () {}, |
25 |
+ getLoginMode: state => state.loginMode, |
|
22 | 26 |
}, |
23 | 27 |
mutations: { |
24 | 28 |
setAuthorization(state, newValue) { |
... | ... | @@ -48,6 +52,7 @@ |
48 | 52 |
setStoreReset(state) { |
49 | 53 |
state.authorization = null; |
50 | 54 |
// state.refresh = null; |
55 |
+ state.loginMode = 'J'; |
|
51 | 56 |
state.mbrNm = null; |
52 | 57 |
state.mbrId = null; |
53 | 58 |
state.roles = [{authority: "ROLE_NONE"}]; |
... | ... | @@ -63,7 +68,10 @@ |
63 | 68 |
}, |
64 | 69 |
setContextPath(state, ctx) { |
65 | 70 |
state.contextPath = ctx; |
66 |
- } |
|
71 |
+ }, |
|
72 |
+ setLoginMode(state, value) { |
|
73 |
+ state.loginMode = value; |
|
74 |
+ }, |
|
67 | 75 |
}, |
68 | 76 |
actions: { |
69 | 77 |
async logout({ commit }) { |
--- client/views/pages/login/Login.vue
+++ client/views/pages/login/Login.vue
... | ... | @@ -108,6 +108,7 @@ |
108 | 108 |
// JWT 방식 |
109 | 109 |
store.commit("setAuthorization", res.headers.authorization); |
110 | 110 |
store.commit("setLoginMode", "J"); |
111 |
+ localStorage.setItem("loginMode", "J"); |
|
111 | 112 |
const base64String = store.state.authorization.split(".")[1]; |
112 | 113 |
const base64 = base64String.replace(/-/g, "+").replace(/_/g, "/"); |
113 | 114 |
const jsonPayload = decodeURIComponent( |
... | ... | @@ -120,18 +121,19 @@ |
120 | 121 |
store.commit("setMbrNm", mbr.mbrNm); |
121 | 122 |
store.commit("setRoles", mbr.roles); |
122 | 123 |
} else if (loginType === 'S') { |
123 |
- // 세션 방식 (서버에서 따로 body에 사용자 정보 내려줘야 함) |
|
124 | 124 |
store.commit("setLoginMode", "S"); |
125 |
+ localStorage.setItem("loginMode", "S"); |
|
125 | 126 |
const mbr = res.data; |
126 | 127 |
store.commit("setAuthorization", null); |
127 | 128 |
store.commit("setMbrId", mbr.mbrId); |
128 | 129 |
store.commit("setMbrNm", mbr.mbrNm); |
129 |
- store.commit("setRoles", mbr.roles); |
|
130 |
+ const roles = mbr.roles.map(r => ({ authority: r.authrtCd })); |
|
131 |
+ store.commit("setRoles", roles); |
|
130 | 132 |
} else { |
131 | 133 |
alert("알 수 없는 로그인 방식입니다."); |
132 | 134 |
return; |
133 | 135 |
} |
134 |
- |
|
136 |
+ const isAdmin = store.state.roles.some(role => role.authority === "ROLE_ADMIN"); |
|
135 | 137 |
let url = this.restoreRedirect("redirect"); |
136 | 138 |
if (url != null && url != "") { |
137 | 139 |
const ctx = store.state.contextPath; |
... | ... | @@ -149,7 +151,9 @@ |
149 | 151 |
this.$router.push({ path: url }); |
150 | 152 |
} |
151 | 153 |
} else { |
152 |
- this.$router.push({ path: this.$filters.ctxPath("/") }); |
|
154 |
+ this.$router.push({ |
|
155 |
+ path: isAdmin ? this.$filters.ctxPath("/adm/main.page") : this.$filters.ctxPath("/") |
|
156 |
+ }); |
|
153 | 157 |
} |
154 | 158 |
|
155 | 159 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?