Handle invalidated application keys after auth failures

This commit is contained in:
2026-04-06 18:31:31 +02:00
parent 35c30120b8
commit 34664be951
7 changed files with 103 additions and 0 deletions
+29
View File
@@ -44,6 +44,7 @@ export function bootstrapApp() {
store,
outlet: document.querySelector('#route-view'),
});
let authFailureHandled = false;
function applyKitchens(kitchens) {
store.setKitchens(kitchens);
@@ -67,6 +68,9 @@ export function bootstrapApp() {
} else if (store.isConnected) {
await window.__loncApp.refreshKitchens();
}
if (store.isConnected) {
authFailureHandled = false;
}
renderNav();
} catch (error) {
renderNav();
@@ -82,11 +86,36 @@ export function bootstrapApp() {
} else if (store.isConnected) {
await window.__loncApp.refreshKitchens();
}
if (store.isConnected) {
authFailureHandled = false;
}
renderNav();
return result;
},
handleAuthFailure(error) {
if (!store.session?.applicationKey || !store.session?.hasValidated || authFailureHandled) {
return;
}
authFailureHandled = true;
store.markSessionInvalid();
renderNav();
const status = error?.status || error?.cause?.status;
const message =
status === 401 || status === 403
? 'This application key is no longer accepted by Tryton. Please verify it again or disconnect and create a new key.'
: 'Authenticated requests are no longer succeeding. The application key may have been cancelled, or access is being denied by the server. Please reconnect or create a new key.';
store.addAlert({
type: 'warning',
timeout: 0,
message,
});
navigate('/login');
window.setTimeout(() => router.render(), 0);
},
async logout() {
await logout(store);
authFailureHandled = false;
renderNav();
navigate('/login');
},
+13
View File
@@ -108,5 +108,18 @@ export function createAppStore() {
this.setKitchens([]);
this.setActiveKitchen(null);
},
markSessionInvalid() {
if (!this.session) {
return;
}
this.setSession({
...this.session,
state: CONNECTION_STATES.invalidKey,
hasValidated: true,
});
this.setKitchens([]);
this.setActiveKitchen(null);
},
};
}