programing

로그아웃 시 nuxt 스토어 및 모든 하위 모듈 지우기

prostudy 2022. 3. 30. 00:09
반응형

로그아웃 시 nuxt 스토어 및 모든 하위 모듈 지우기

사용자가 로그아웃하면 스토어를 모두 리셋할 수 있는 가장 좋은 솔루션이 무엇인지 궁금하다.일반적으로 나는 로그인하는 앱이 있고 때때로 개발 모드에 있는 나는 계정에서 전환해야 한다(실시간 모드의 경우가 있다.그리고 분명히 나는 다른 사용자들과 로그인을 할 때 약간의 문제가 있다. 어떤 상점 인포들은 여전히 그곳에 있고 다른 사용자들의 것이다.나는 이미 내 상점에서 auth.js 내의 logout 기능 안에 있는 모듈을 지웠다.하지만 내 앱이 성장하고 있고, 저장(여러 모듈에서 분리됨) 또한 초기 가치/상태와 함께 모든 저장소를 한 번에 재설정할 수 있는 최선의 방법이 무엇인지 궁금할 뿐이다.

무슨 생각 있어?

이것이 내가 Nuxt에 있는 상점에서 몇 가지 자료를 정리하는 방법이다.

clearToken(state) {
   state.token = null
   state.refresh = null
   state.currentUserData = null
},

logout(vuexContext, req) {
    vuexContext.commit('clearToken')
    Cookie.remove('jwt')
    Cookie.remove('jwt_refresh')
    Cookie.remove("tokenExpiration");
    Cookie.remove("userData");
    if (process.client) {
      localStorage.removeItem('refresh');
      localStorage.removeItem('token');
      localStorage.removeItem("tokenExpiration");
      localStorage.removeItem("userData");
    if (!localStorage.getItem('token')) {
      $nuxt.$router.push('/login/');
    }
  }
}

다음을 사용하여 모든 vuex 데이터를 치료할 수 있다.localStorage.vuex = ''

참조URL: https://stackoverflow.com/questions/52698378/clear-nuxt-store-and-all-submodules-at-logout

반응형