[core] prevent recursive logouts on htto-401

fixes #7
This commit is contained in:
groegert 2021-05-24 19:21:49 +02:00
parent f2b7f3a3b4
commit 9940589d1a
3 changed files with 14 additions and 10 deletions

View File

@ -22,7 +22,7 @@ export default boot(({ router }) => {
/*** /***
* Intercept responses * Intercept responses
* - filter 401 --> logout * - filter 401 --> handleLoggedOut
* - filter timeout or 502-504 --> backendOffline * - filter timeout or 502-504 --> backendOffline
*/ */
api.interceptors.response.use( api.interceptors.response.use(
@ -45,7 +45,7 @@ export default boot(({ router }) => {
query: { redirect: next }, query: { redirect: next },
}); });
} else if (e.response && e.response.status == 401) { } else if (e.response && e.response.status == 401) {
void store.logout(); void store.handleLoggedOut();
if (current.name !== 'login') { if (current.name !== 'login') {
await router.push({ await router.push({
name: 'login', name: 'login',

View File

@ -10,7 +10,8 @@ const config: { [key: string]: Array<string> } = {
// Do not change required Modules !! // Do not change required Modules !!
requiredModules: ['User'], requiredModules: ['User'],
// here you can import plugins. // here you can import plugins.
loadModules: ['Balance', 'Schedule', 'Pricelist'], //loadModules: ['Balance', 'Schedule', 'Pricelist'],
loadModules: [],
}; };
/* Stop! /* Stop!

View File

@ -76,19 +76,13 @@ export const useMainStore = defineStore({
async logout() { async logout() {
if (!this.session || !this.session.token) return false; if (!this.session || !this.session.token) return false;
LocalStorage.clear();
try { try {
const token = this.session.token; const token = this.session.token;
await api.delete(`/auth/${token}`); await api.delete(`/auth/${token}`);
this.$patch({
session: undefined,
user: undefined,
});
} catch (error) { } catch (error) {
return false; return false;
} finally { } finally {
SessionStorage.clear(); this.handleLoggedOut( );
} }
return true; return true;
}, },
@ -151,6 +145,15 @@ export const useMainStore = defineStore({
async setShortcuts() { async setShortcuts() {
await api.put(`users/${this.currentUser.userid}/shortcuts`, this.shortcuts); await api.put(`users/${this.currentUser.userid}/shortcuts`, this.shortcuts);
}, },
handleLoggedOut() {
LocalStorage.clear();
this.$patch({
session: undefined,
user: undefined,
});
SessionStorage.clear();
},
}, },
}); });