diff --git a/src/api/member.js b/src/api/member.js index 68c5bcd..93dd849 100644 --- a/src/api/member.js +++ b/src/api/member.js @@ -12,10 +12,12 @@ async function findByToken(userid,token, success, fail) { await local.get(`/member/info/${userid}`).then(success).catch(fail); } -async function tokenRegeneration(user, success, fail) { +async function tokenRegeneration(userid,token, success, fail) { // local.defaults.headers["refreshToken"] = sessionStorage.getItem("refreshToken"); //axios header에 refresh-token 셋팅 - local.defaults.headers["refreshToken"] = localStorage.getItem("refreshToken"); - await local.post(`/member/refresh`, user).then(success).catch(fail); + local.defaults.headers["refreshToken"] = token + console.log(userid) + console.log(token) + await local.post(`/member/refresh/${userid}`).then(success).catch(fail); } async function logout(userid, success, fail) { diff --git a/src/router/index.js b/src/router/index.js index 232c2f9..d093ce2 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -7,17 +7,24 @@ import { useMemberStore } from '@/stores/memberStore'; const onlyAuthUser = async (to, from, next) => { const memberStore = useMemberStore(); - const { userInfo, isValidToken } = storeToRefs(memberStore); - const { getUserInfo } = memberStore; + const { userInfo, isLogin } = storeToRefs(memberStore); + const { isValidToken } = memberStore; - let token = sessionStorage.getItem('accessToken'); - - if (userInfo.value != null && token) { - await getUserInfo(token); + let token = localStorage.getItem("accessToken"); + console.log(userInfo) + console.log(isLogin) + // if (userInfo.value != null && token) { + console.log(isLogin.value) + console.log(token) + if (isLogin.value != null && token) { + console.log("이프문들어옴") + await isValidToken(token); } - if (!isValidToken.value || userInfo.value === null) { - next({ name: 'user-login' }); + if (isLogin.value === null) { + console.log("이프문2들어옴") + next({ name: "user-login" }); } else { + console.log("else문 들어옴") next(); } }; @@ -90,6 +97,10 @@ const router = createRouter({ }, ], }, + { + path: '/test', + component: () => import('@/views/TestView.vue'), + }, ], }); diff --git a/src/stores/memberStore.js b/src/stores/memberStore.js index 92cfd1b..9ef9478 100644 --- a/src/stores/memberStore.js +++ b/src/stores/memberStore.js @@ -30,9 +30,11 @@ export const useMemberStore = defineStore("memberStore", () => { } const isValidToken = async (token) => { - const {id} = jwtDecode(token); - findByToken(id,token, () => { }, (error) => { + const { userId } = jwtDecode(token); + console.log(userId,token) + findByToken(userId,token, () => { }, (error) => { console.log(error); + console.log("tokenRegenerate") tokenRegenerate(); }) @@ -40,13 +42,18 @@ export const useMemberStore = defineStore("memberStore", () => { const tokenRegenerate = async () => { + const { userId } = jwtDecode(accessToken.value) const refreshToken = localStorage.getItem('refreshToken'); + console.log(userId) + console.log(refreshToken) await tokenRegeneration( - refreshToken, + userId,refreshToken, (response) => { if (response.status === httpStatusCode.CREATE) { const newAccessToken = response.data["access-token"] + const newRefreshToken = response.data["refresh-token"] localStorage.setItem("accessToken", newAccessToken) + localStorage.setItem("refreshToken", newRefreshToken) accessToken.value = newAccessToken; } },