Fix inactivity detection followed by logout - Fixes #267

This commit is contained in:
Bubka
2024-03-06 08:40:29 +01:00
parent 214c1c2349
commit 9519d5838c
3 changed files with 11 additions and 14 deletions

View File

@ -51,6 +51,15 @@ export const httpClientFactory = (endpoint = 'api') => {
await axios.get('/refresh-csrf')
return httpClient.request(originalRequestConfig)
}
// api calls are stateless so when user inactivity is detected
// by the backend middleware, it cannot logout the user directly
// so it returns a 418 response.
// We catch the 418 response and log the user out
if (error.response.status === 418) {
const user = useUserStore()
user.logout({ kicked: true})
}
if (error.response && [407].includes(error.response.status)) {
useNotifyStore().error(error)
@ -78,15 +87,6 @@ export const httpClientFactory = (endpoint = 'api') => {
return new Promise(() => {})
}
// api calls are stateless so when user inactivity is detected
// by the backend middleware, it cannot logout the user directly
// so it returns a 418 response.
// We catch the 418 response and log the user out
if (error.response.status === 418) {
const user = useUserStore()
user.logout({ kicked: true})
}
useNotifyStore().error(error)
return new Promise(() => {})
}