Skip to content

Commit f0e0cd0

Browse files
committed
fix: refresh access token before issuing request
1 parent edc3234 commit f0e0cd0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/commands/api/request/graphql.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export default class Graphql extends SfCommand<void> {
4545
.replaceAll('"', '\\"')}"}`;
4646
const url = new URL(`${org.getField<string>(Org.Fields.INSTANCE_URL)}/services/data/v${apiVersion}/graphql`);
4747

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

5052
const options = {

src/commands/api/request/rest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export class Rest extends SfCommand<void> {
138138
headers = { ...headers, ...body.getHeaders() };
139139
}
140140

141+
// refresh access token to ensure `got` gets a valid access token.
142+
// TODO: we could skip this step if we used jsforce's HTTP module instead (handles expired tokens).
143+
await org.refreshAuth();
144+
141145
const options = {
142146
agent: { https: new ProxyAgent() },
143147
method,
@@ -155,8 +159,6 @@ export class Rest extends SfCommand<void> {
155159
followRedirect: false,
156160
};
157161

158-
await org.refreshAuth();
159-
160162
await sendAndPrintRequest({ streamFile, url, options, include: flags.include, this: this });
161163
}
162164
}

0 commit comments

Comments
 (0)