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