From 7548fe36db0d9a67eec4bafc806282df7947619b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 19 Mar 2025 21:17:34 -0400 Subject: [PATCH] Remove use of Promise.any --- server/queues/tasks/ValidateSSOAccessTask.ts | 31 ++++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/server/queues/tasks/ValidateSSOAccessTask.ts b/server/queues/tasks/ValidateSSOAccessTask.ts index 4a38523ab8..d90283ffc5 100644 --- a/server/queues/tasks/ValidateSSOAccessTask.ts +++ b/server/queues/tasks/ValidateSSOAccessTask.ts @@ -19,26 +19,19 @@ export default class ValidateSSOAccessTask extends BaseTask { return; } - try { - // Check the validity of all the user's associated authentications. - // @ts-expect-error TODO: Need to setup nested tsconfig with ES2021 - const valid = await Promise.any( - userAuthentications.map(async (authentication) => - authentication.validateAccess({ transaction }) - ) - ); + // Check the validity of the user's authentications. + const validity = await Promise.all( + userAuthentications.map(async (authentication) => { + try { + return await authentication.validateAccess({ transaction }); + } catch (err) { + return false; + } + }) + ); - // If any are valid then we're done here. - if (valid) { - return; - } - } catch (err) { - // Promise.any will throw an AggregateError if all validateAccess calls throw, this would - // only be the case if all receive an unexpected error. We want to throw the first error - // as a descriptive error message. - if ("errors" in err && err.errors.length > 0) { - throw err.errors[0]; - } + if (validity.some((isValid) => isValid)) { + return; } // If all are invalid then we need to revoke the users Outline sessions.