diff --git a/src/components/auth/Login.vue b/src/components/auth/Login.vue index 3fb919f459e741e96abc3d922e4945b8714a2f0d..a6212d380953da0a78aeaefe9b514aeb50e089a9 100644 --- a/src/components/auth/Login.vue +++ b/src/components/auth/Login.vue @@ -21,10 +21,11 @@ export default { methods:{ async login() { - // if (!this.id || !this.password) { - // return; - // } - + // await this.$store.dispatch('getUser'); + // // if (!this.id || !this.password) { + // // return; + // // } + // // CryptoJS SHA256 toUpperCase 적용 const passwordHash = CryptoJS.SHA256(this.password).toString().toUpperCase(); // Hash the password console.log(passwordHash) @@ -55,19 +56,7 @@ export default { }, async logout() { - const response = await logout.logout(); - - console.log(response) - - // 로그인 상태일때 "로그아웃" 실행 - if(response.status === 200){ - // user 값을 빈객체 null 혹은 {} 로 clear 해주기 - this.$store.commit("setUserData", {}); - console.log("로그아웃 성공") - }else{ - console.log("로그아웃 실패") - } - + await this.$store.dispatch('clearUser'); }, }, diff --git a/src/store/store.js b/src/store/store.js index 79a44f8420e57e9148c62f62811d421f430cbdd7..38fb83138eb4ec0b41bdb03004fc172feaf89a86 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -1,11 +1,15 @@ import {createStore} from 'vuex' import fetchData from "@/store/fetchData.js"; +import CryptoJS from "crypto-js"; +import logout from "@/store/logout.js"; const store = createStore({ state(){ return{ user:{}, + id:"", + password:"" } }, actions:{ @@ -25,6 +29,40 @@ const store = createStore({ // } // } + // async getUser(){ + // const passwordHash=CryptoJS.SHA256(this.password).toString().toUpperCase() + // console.log(passwordHash) + // const loginData={ + // id:this.id, + // password:passwordHash + // } + // // 여기서 문제인듯한데 + // const response = await fetchData.login(loginData); + // console.log(response) + // + // if(response){ + // this.commit("setUserData",response.data.data.user); + // console.log("스토어로 로그인에 성공") + // }else{ + // console.log("스토어로 로그인에 실패") + // } + // + // } + + async clearUser(){ + const response = await logout.logout(); + + console.log(response) + + // 로그인 상태일때 "로그아웃" 실행 + if(response.status === 200){ + // user 값을 빈객체 null 혹은 {} 로 clear 해주기 + this.commit("setUserData", {}); + console.log("로그아웃 성공") + }else{ + console.log("로그아웃 실패") + } + } }, @@ -37,8 +75,10 @@ const store = createStore({ // }, mutations:{ setUserData(state,userData){ - state.user=userData - } + state.user = userData + }, + + } }) export default store; \ No newline at end of file