Reset the user store on unauthenticated HTTP response

This commit is contained in:
Bubka 2023-09-28 13:23:58 +02:00
parent 73e36edd9c
commit fe9002501b
2 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import axios from "axios"
import { useUserStore } from '@/stores/user'
export const httpClientFactory = (endpoint = 'api') => {
let baseURL
@ -26,10 +27,9 @@ export const httpClientFactory = (endpoint = 'api') => {
if (
error.response &&
[401, 419].includes(error.response.status)
// && store.getters["auth/authUser"] &&
// !store.getters["auth/guest"]
) {
// store.dispatch("auth/logout");
const user = useUserStore()
user.reset()
}
return Promise.reject(error);
}

View File

@ -34,14 +34,18 @@ export const useUserStore = defineStore({
}
else {
return authService.logout().then(() => {
localStorage.clear()
this.$reset()
router.push({ name: 'login' })
this.reset()
})
// this.$router.push({ name: 'login', params: { forceRefresh: true } })
}
// },
},
reset() {
localStorage.clear()
this.$reset()
router.push({ name: 'login' })
}
},