mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-27 15:32:06 +02:00
Reset the user store on unauthenticated HTTP response
This commit is contained in:
parent
73e36edd9c
commit
fe9002501b
@ -1,4 +1,5 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
|
import { useUserStore } from '@/stores/user'
|
||||||
|
|
||||||
export const httpClientFactory = (endpoint = 'api') => {
|
export const httpClientFactory = (endpoint = 'api') => {
|
||||||
let baseURL
|
let baseURL
|
||||||
@ -26,10 +27,9 @@ export const httpClientFactory = (endpoint = 'api') => {
|
|||||||
if (
|
if (
|
||||||
error.response &&
|
error.response &&
|
||||||
[401, 419].includes(error.response.status)
|
[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);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
10
resources/js_vue3/stores/user.js
vendored
10
resources/js_vue3/stores/user.js
vendored
@ -34,14 +34,18 @@ export const useUserStore = defineStore({
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return authService.logout().then(() => {
|
return authService.logout().then(() => {
|
||||||
localStorage.clear()
|
this.reset()
|
||||||
this.$reset()
|
|
||||||
router.push({ name: 'login' })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// this.$router.push({ name: 'login', params: { forceRefresh: true } })
|
// this.$router.push({ name: 'login', params: { forceRefresh: true } })
|
||||||
}
|
}
|
||||||
// },
|
// },
|
||||||
|
},
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
localStorage.clear()
|
||||||
|
this.$reset()
|
||||||
|
router.push({ name: 'login' })
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user