Skip to content

Commit

Permalink
fix: refresh access token before issuing request
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 committed Jan 15, 2025
1 parent edc3234 commit f0e0cd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/commands/api/request/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export default class Graphql extends SfCommand<void> {
.replaceAll('"', '\\"')}"}`;
const url = new URL(`${org.getField<string>(Org.Fields.INSTANCE_URL)}/services/data/v${apiVersion}/graphql`);

// refresh access token to ensure `got` gets a valid access token.
// TODO: we could skip this step if we used jsforce's HTTP module instead (handles expired tokens).
await org.refreshAuth();

const options = {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/api/request/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class Rest extends SfCommand<void> {
headers = { ...headers, ...body.getHeaders() };
}

// refresh access token to ensure `got` gets a valid access token.
// TODO: we could skip this step if we used jsforce's HTTP module instead (handles expired tokens).
await org.refreshAuth();

const options = {
agent: { https: new ProxyAgent() },
method,
Expand All @@ -155,8 +159,6 @@ export class Rest extends SfCommand<void> {
followRedirect: false,
};

await org.refreshAuth();

await sendAndPrintRequest({ streamFile, url, options, include: flags.include, this: this });
}
}
Expand Down

0 comments on commit f0e0cd0

Please sign in to comment.