
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
... | ... | @@ -7,6 +7,8 @@ |
7 | 7 |
import FeedBack from "./subPage/FeedBack.vue"; |
8 | 8 |
import Find from "./common/Find.vue"; |
9 | 9 |
import Join from "./common/Join.vue"; |
10 |
+import AppStore from "./AppStore"; |
|
11 |
+ |
|
10 | 12 |
|
11 | 13 |
const routes = [ |
12 | 14 |
{ |
... | ... | @@ -29,4 +31,22 @@ |
29 | 31 |
routes, |
30 | 32 |
}); |
31 | 33 |
|
34 |
+AppRouter.beforeEach((to, from, next) => { |
|
35 |
+ const isLoggedIn = !!AppStore.state.authorization; |
|
36 |
+ |
|
37 |
+ const publicPages = ['/login.page', '/find.page', '/join.page']; |
|
38 |
+ const isPublic = publicPages.includes(to.path); |
|
39 |
+ |
|
40 |
+ if (!isLoggedIn && !isPublic) { |
|
41 |
+ // 로그인 안 되어 있는데 비공개 페이지 접근 → 로그인 페이지로 |
|
42 |
+ next({ path: '/login.page' }); |
|
43 |
+ } else if (isLoggedIn && to.path === '/login.page') { |
|
44 |
+ // 로그인 상태에서 로그인 페이지 접근 시 메인으로 리다이렉트 |
|
45 |
+ next({ path: '/' }); |
|
46 |
+ } else { |
|
47 |
+ next(); // 정상 접근 |
|
48 |
+ } |
|
49 |
+}); |
|
50 |
+ |
|
51 |
+ |
|
32 | 52 |
export default AppRouter;(파일 끝에 줄바꿈 문자 없음) |
--- client/views/pages/main/Main.vue
+++ client/views/pages/main/Main.vue
... | ... | @@ -57,6 +57,7 @@ |
57 | 57 |
</template> |
58 | 58 |
|
59 | 59 |
<script> |
60 |
+import { mapGetters } from 'vuex'; |
|
60 | 61 |
|
61 | 62 |
export default { |
62 | 63 |
data() { |
... | ... | @@ -84,10 +85,18 @@ |
84 | 85 |
}, |
85 | 86 |
methods: {}, |
86 | 87 |
watch: {}, |
87 |
- computed: {}, |
|
88 |
+ computed: { |
|
89 |
+ ...mapGetters([ |
|
90 |
+ 'getMemId', |
|
91 |
+ 'getMemNm', |
|
92 |
+ 'getMemLoginId' |
|
93 |
+ ]) |
|
94 |
+ }, |
|
88 | 95 |
components: {}, |
89 | 96 |
created() {}, |
90 |
- mounted() {}, |
|
97 |
+ mounted() { |
|
98 |
+ console.log("사용자 아이디: " + this.getMemId + " 사용자 이름: " + this.getMemNm + " 사용자 로그인 아이디: " + this.getMemLoginId); |
|
99 |
+ }, |
|
91 | 100 |
beforeUnmount() {}, |
92 | 101 |
}; |
93 | 102 |
|
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?