From 3a63bb76eaf33555253045ce8b99f97ba8d5507e Mon Sep 17 00:00:00 2001 From: Ben Waples Date: Fri, 2 Aug 2024 10:37:39 -0700 Subject: [PATCH 1/3] fix: logout on 401 /features --- cmd/ui/src/utils.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/ui/src/utils.ts b/cmd/ui/src/utils.ts index 465999d6ef..f3a955b9ca 100644 --- a/cmd/ui/src/utils.ts +++ b/cmd/ui/src/utils.ts @@ -25,6 +25,8 @@ import { isLink, isNode } from 'src/ducks/graph/utils'; import { Glyph } from 'src/rendering/programs/node.glyphs'; import { store } from 'src/store'; +const IGNORE_401_LOGOUT = ['/api/v2/login', '/api/v2/logout', '/api/v2/features'] + export const getDatesInRange = (startDate: Date, endDate: Date) => { const date = new Date(startDate.getTime()); @@ -74,11 +76,8 @@ export const initializeBHEClient = () => { (error) => { if (error?.response) { - if ( - error?.response?.status === 401 && - error?.response?.config.url !== '/api/v2/login' && - error?.response?.config.url !== '/api/v2/logout' - ) { + if (error?.response?.status === 401) { + if (IGNORE_401_LOGOUT.includes(error?.response?.config.url)) return throttledLogout(); } else if ( error?.response?.status === 403 && From c1a696f1fb2708bb57f32484b5a5395e015a7fc2 Mon Sep 17 00:00:00 2001 From: Ben Waples Date: Fri, 2 Aug 2024 13:57:38 -0700 Subject: [PATCH 2/3] refactor: reject with error instead of early return --- cmd/ui/src/utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/ui/src/utils.ts b/cmd/ui/src/utils.ts index f3a955b9ca..3e98e32266 100644 --- a/cmd/ui/src/utils.ts +++ b/cmd/ui/src/utils.ts @@ -77,8 +77,9 @@ export const initializeBHEClient = () => { (error) => { if (error?.response) { if (error?.response?.status === 401) { - if (IGNORE_401_LOGOUT.includes(error?.response?.config.url)) return - throttledLogout(); + if (!IGNORE_401_LOGOUT.includes(error?.response?.config.url)) { + throttledLogout(); + } } else if ( error?.response?.status === 403 && !error?.response?.config.url.match('/api/v2/bloodhound-users/[a-z0-9-]+/secret') From 7bb4cdc456a712697ade5c352e8e7312f0c3abdb Mon Sep 17 00:00:00 2001 From: Ben Waples Date: Fri, 2 Aug 2024 14:01:30 -0700 Subject: [PATCH 3/3] refactor: replace bang operator --- cmd/ui/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ui/src/utils.ts b/cmd/ui/src/utils.ts index 3e98e32266..fdb6579f39 100644 --- a/cmd/ui/src/utils.ts +++ b/cmd/ui/src/utils.ts @@ -77,7 +77,7 @@ export const initializeBHEClient = () => { (error) => { if (error?.response) { if (error?.response?.status === 401) { - if (!IGNORE_401_LOGOUT.includes(error?.response?.config.url)) { + if (IGNORE_401_LOGOUT.includes(error?.response?.config.url) === false) { throttledLogout(); } } else if (