From 95f0fbdb5e99abd8d17f931f3b5752d466d0c438 Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Sat, 14 Sep 2024 19:11:53 +0000 Subject: [PATCH] api-client/turnstile: don't retry making session if it's not needed --- packages/api-client/src/turnstile-api.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/api-client/src/turnstile-api.ts b/packages/api-client/src/turnstile-api.ts index e52c97e1..a50e7c0d 100644 --- a/packages/api-client/src/turnstile-api.ts +++ b/packages/api-client/src/turnstile-api.ts @@ -26,17 +26,20 @@ export class TurnstileCobaltAPI extends CobaltAPI { } async request(data: CobaltRequest) { - const sessionOrError = await this.#session.getSession(); const headers: Record = {}; - if ("error" in sessionOrError) { - if (sessionOrError.error.code !== CobaltAuthError.NotConfigured) { - return sessionOrError; + if (this.#instanceHasTurnstile) { + const sessionOrError = await this.#session.getSession(); + + if ("error" in sessionOrError) { + if (sessionOrError.error.code !== CobaltAuthError.NotConfigured) { + return sessionOrError; + } else { + this.#instanceHasTurnstile = false; + } } else { - this.#instanceHasTurnstile = false; + headers['Authorization'] = `Bearer ${sessionOrError.token}`; } - } else { - headers['Authorization'] = `Bearer ${sessionOrError.token}`; } return super.request(data, headers);