Handle invalidated application keys after auth failures
This commit is contained in:
Vendored
+29
@@ -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');
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user