From c82ef343f9598de6902a8428530efab3a2874cf2 Mon Sep 17 00:00:00 2001 From: spaenleh Date: Mon, 4 Mar 2024 16:30:18 +0100 Subject: [PATCH] fix: add handling of denied app access --- src/items/appItemHooks.ts | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/items/appItemHooks.ts b/src/items/appItemHooks.ts index bd8e2c7fe..91af04ef0 100644 --- a/src/items/appItemHooks.ts +++ b/src/items/appItemHooks.ts @@ -71,16 +71,34 @@ const useAppCommunication = ({ switch (type) { case POST_MESSAGE_KEYS.GET_AUTH_TOKEN: { - // eslint-disable-next-line no-unused-expressions - port.postMessage( - JSON.stringify({ - type: POST_MESSAGE_KEYS.GET_AUTH_TOKEN_SUCCESS, - payload: await requestApiAccessToken({ + const { key, origin } = payload; + if (key && origin) { + try { + const payload = await requestApiAccessToken({ id: item.id, - ...payload, - }), - }), - ); + key, + origin, + }); + port.postMessage( + JSON.stringify({ + type: POST_MESSAGE_KEYS.GET_AUTH_TOKEN_SUCCESS, + payload, + }), + ); + } catch { + console.error('error getting api access token'); + port.postMessage( + JSON.stringify({ + type: POST_MESSAGE_KEYS.GET_AUTH_TOKEN_FAILURE, + }), + ); + } + } else { + console.error( + '`key` or `origin` were not specified in the request to get the auth token', + payload, + ); + } break; }