From 2ae67a28fbac8f17105d144da291dad82ecbc919 Mon Sep 17 00:00:00 2001 From: huw Date: Wed, 11 Oct 2023 12:05:30 +1100 Subject: [PATCH] =?UTF-8?q?Use=20`btoa`=20when=20`Buffer`=20isn=E2=80=99t?= =?UTF-8?q?=20available?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Client.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Client.ts b/src/Client.ts index 338807b9..88d6ad1c 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -186,7 +186,10 @@ export default class Client { // authorization header as required by `Basic` auth. const unencodedCredential = `${auth.client_id}:${auth.client_secret}` const encodedCredential = - Buffer.from(unencodedCredential).toString("base64") + typeof Buffer !== "undefined" + ? Buffer.from(unencodedCredential).toString("base64") + // Use `btoa` in non-Node environments + : btoa(unencodedCredential) authorizationHeader = { authorization: `Basic ${encodedCredential}` } } else { // Otherwise format authorization header as `Bearer` token auth.