From 8b85265ca4ccc16a4ebcc7636ce8d872d95702b0 Mon Sep 17 00:00:00 2001 From: James Gatz Date: Mon, 2 Oct 2023 13:45:08 +0200 Subject: [PATCH] do not try to post to /logout if not logged in and make it fire and forget (#6619) --- packages/insomnia/src/account/session.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/insomnia/src/account/session.ts b/packages/insomnia/src/account/session.ts index 5e068a1f6..15c24bcd8 100644 --- a/packages/insomnia/src/account/session.ts +++ b/packages/insomnia/src/account/session.ts @@ -200,16 +200,19 @@ export function isLoggedIn() { /** Log out and delete session data */ export async function logout() { - try { - await window.main.insomniaFetch({ - method: 'POST', - path: '/auth/logout', - sessionId: getCurrentSessionId(), - }); - } catch (error) { - // Not a huge deal if this fails, but we don't want it to prevent the - // user from signing out. - console.warn('Failed to logout', error); + const sessionId = getCurrentSessionId(); + if (sessionId) { + try { + window.main.insomniaFetch({ + method: 'POST', + path: '/auth/logout', + sessionId, + }); + } catch (error) { + // Not a huge deal if this fails, but we don't want it to prevent the + // user from signing out. + console.warn('Failed to logout', error); + } } _unsetSessionData();