Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ export class Authenticator {
});

try {
this.accessToken = undefined;

const { access_token } = await httpClient
.request<{
access_token: string;
}>("POST", url, { body, retry: false })
.ready();
this.accessToken = access_token;
} catch (error) {
console.log("Failed to refresh access token");
console.error(error);
console.log("Performing login...");
await this.authenticate();
}
}
Expand All @@ -61,6 +66,8 @@ export class Authenticator {
password
});

this.accessToken = undefined;

const { access_token, refresh_token } = await httpClient
.request<Login>("POST", url, {
body,
Expand Down
6 changes: 3 additions & 3 deletions src/http/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ export class NodeHttpClient {

const withProtocol = assignProtocol(url);

const userAgent = headers["user-agent"] || DEFAULT_USER_AGENT;
const response = await fetch(withProtocol, {
agent,
signal: controller.signal as AbortSignal,
method,
headers: {
"user-agent": headers["user-agent"]
? headers["user-agent"]
: DEFAULT_USER_AGENT,
"user-agent": userAgent,
"Content-Type": "application/json",
...headers
},
Expand All @@ -70,6 +69,7 @@ export class NodeHttpClient {
try {
await this.authenticator.refreshAccessToken();
} catch (error) {
console.error(error);
throw new AuthenticationError({
message: "Failed to refresh access token"
});
Expand Down