From ab6fcfb4379ddf6125e68b10cdf8116b34f8f155 Mon Sep 17 00:00:00 2001 From: jihyun jo Date: Wed, 31 Jan 2024 14:33:08 +0900 Subject: [PATCH] =?UTF-8?q?logout=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/auth/Login.vue | 14 ++++---------- src/store/logout.js | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/components/auth/Login.vue b/src/components/auth/Login.vue index 32330e8..3fb919f 100644 --- a/src/components/auth/Login.vue +++ b/src/components/auth/Login.vue @@ -2,6 +2,7 @@ import axios from "axios"; import CryptoJS from "crypto-js"; import fetchData from "@/store/fetchData"; +import logout from "@/store/logout.js"; export default { @@ -52,24 +53,17 @@ export default { } }, - async logout() { - // await logout.logout(); - // fetch 해서 login 정보의 access 토큰을 들고와서 : 나중에 fetchData 분리 처리 - const response = await axios.get("https://172.16.0.60:8443/api/auth/logout", { - headers: { - // accessToken 을 들고온 값을 여기 넣어주고 - "Authorization": `Bearer ${this.$store.state.user.info.accessToken}`, - }, + async logout() { + const response = await logout.logout(); - }) console.log(response) // 로그인 상태일때 "로그아웃" 실행 if(response.status === 200){ // user 값을 빈객체 null 혹은 {} 로 clear 해주기 this.$store.commit("setUserData", {}); - console.log("로그아웃") + console.log("로그아웃 성공") }else{ console.log("로그아웃 실패") } diff --git a/src/store/logout.js b/src/store/logout.js index 401feb7..db02c3a 100644 --- a/src/store/logout.js +++ b/src/store/logout.js @@ -1,26 +1,28 @@ import axios from "axios"; +import store from "@/store/store.js"; // 로그인되어있는 상태에서 accessToken 값을 뽑아와서 header 에 실어보내 매칭시키고 clear 로 export default { async logout() { // fetch 해서 login 정보의 access 토큰을 들고와서 : 나중에 fetchData 분리 처리 - const response = await axios.get("https://172.16.0.60:8443/api/auth/logout", { + return await axios.get("https://172.16.0.60:8443/api/auth/logout", { headers: { // accessToken 을 들고온 값을 여기 넣어주고 - "Authorization": `Bearer ${this.$store.state.user.info.accessToken}`, + // this.$store 가 인식되지 않아 state 오류가 났고 store 를 import 해주었다. + "Authorization": `Bearer ${store.state.user.info.accessToken}`, }, }) - console.log(response) - - // 로그인 상태일때 "로그아웃" 실행 - if(response.status === 200){ - // user 값을 빈객체 null 혹은 {} 로 clear 해주기 - this.$store.commit("setUserData", {}); - console.log("로그아웃") - }else{ - console.log("로그아웃 실패") - } + // console.log(response) + // + // // 로그인 상태일때 "로그아웃" 실행 + // if(response.status === 200){ + // // user 값을 빈객체 null 혹은 {} 로 clear 해주기 + // this.$store.commit("setUserData", {}); + // console.log("로그아웃 성공") + // }else{ + // console.log("로그아웃 실패") + // } }, }; -- GitLab