Skip to content
Open
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
11 changes: 11 additions & 0 deletions change/change-e750e299-3f52-4757-8968-fb45d7ecf356.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "patch",
"comment": "Fix circular promise in fetchTokens",
"packageName": "@microsoft/yarn-plugin-ado-auth",
"email": "[email protected]",
"dependentChangeType": "patch"
}
]
}
9 changes: 6 additions & 3 deletions packages/yarn-plugin-ado-auth/src/tokenCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class TokenCache {
*/
private async fetchToken(registry: string, ident?: Ident): Promise<string> {
const configuration = this.configuration;
let token: string | null = null;

await StreamReport.start(
{ configuration, stdout: process.stdout },
async (report) => {
Expand All @@ -70,6 +72,7 @@ export class TokenCache {
const authConfig = this.getAuthConfiguration(registry, ident);
const tokenFromYarnrc = getConfigString(authConfig, "npmAuthToken");
if (tokenFromYarnrc) {
token = tokenFromYarnrc;
this.cache[registry] = tokenFromYarnrc;
report.reportInfo(
null,
Expand All @@ -91,6 +94,7 @@ export class TokenCache {
false,
this.azureAuthPath,
);
token = pat;
this.cache[registry] = pat;
report.reportInfo(
null,
Expand All @@ -99,11 +103,10 @@ export class TokenCache {
},
);

const pat = this.cache[registry];
if (pat == null) {
if (token == null) {
throw new Error(`Failed to authenticate to: ${registry}`);
}
return pat;
return token;
}

/**
Expand Down