Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): stay on the page for a keyless request (#1853)
Yudhi Armyndharisfe3860c09a9c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d199b3731..bd2a34e84 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- Stop a request left over from before logout from reloading the dashboard login form.- Stop a dashboard Logs export from downloading rows after sign-out when its last page was throttled.- Stop reopening a just-saved dashboard template from loading its old values, which a second save wrote back.- Stop an operator webhook redrive at its next row on shutdown.diff --git a/dashboard/src/services/api.test.ts b/dashboard/src/services/api.test.tsindex 4458390fe..0019868ff 100644--- a/dashboard/src/services/api.test.ts+++ b/dashboard/src/services/api.test.ts@@ -167,12 +167,13 @@ for (const [status, message] of keyFailures) {});}-test('a 401 for a request sent without a key while none is stored returns to login', async () => {+test('a 401 for a request sent without a key while none is stored stays silent on the login form', async () => {sessionStorage.removeItem('openwa_api_key');answer(401, 'API key is required');const result = sessionApi.list();assert.equal(await settled(result), false, 'the call settled, so its caller would render the failure');- assert.deepEqual(navigations, ['/']);+ assert.equal(sessionStorage.getItem('openwa_api_key'), null);+ assert.deepEqual(navigations, []);});test('a late 401 for a request sent while signed out keeps the key signed in since', stale, async () => {diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.tsindex 1e576b659..ba4b5cb64 100644--- a/dashboard/src/services/api.ts+++ b/dashboard/src/services/api.ts@@ -743,8 +743,11 @@ export interface SearchResults {// `sentKey` is the key the request carried (null when none). Logout aborts nothing in flight, so an// answer can arrive after the stored key changed. With a key sent but none stored, a sign-out is// already under way (an earlier failure of the same burst, or the user on the login form): stay-// silent and do not navigate again. With another key stored, the answer speaks for a key no longer-// in use and must not sign out the current one, so it fails like any other error.+// silent and do not navigate again. A request sent without a key comes only from a chain that+// outlived a logout (the dashboard shows the login form whenever no key is stored), so with none+// stored it stays silent too rather than reloading the login form under the user. With another key+// stored, the answer speaks for a key no longer in use and must not sign out the current one, so it+// fails like any other error.async function handleErrorResponse<T>(response: Response, sentKey: string | null): Promise<T> {// On a non-JSON body (e.g. a reverse-proxy 502/503/504 HTML page) fall through to `HTTP <status>`// rather than statusText: the toast folds an exact `HTTP 502`/`HTTP 503` into its connection-lost@@ -754,7 +757,7 @@ async function handleErrorResponse<T>(response: Response, sentKey: string | nullif (isKeyUnusable(response.status, error.message) && (storedKey === sentKey || storedKey === null)) {sessionStorage.removeItem('openwa_api_key');if (typeof window !== 'undefined') {- if (storedKey === sentKey) window.location.assign('/');+ if (sentKey !== null && storedKey === sentKey) window.location.assign('/');return new Promise<T>(() => {});}}