Skip to content

Commit 434ff39

Browse files
committed
fix(provider): let meta oauth profiles sign in again
1 parent 4fcc0a1 commit 434ff39

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

‎src/tui/provider-setup.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,23 @@ describe("provider setup pure helpers", () => {
343343
expect(suggestMetaOAuthProfileSlug([], ["meta/default"])).toBe("default-2");
344344
expect(suggestMetaOAuthProfileSlug([], [])).toBe("default");
345345
expect(metaOAuthSlugBlockedByApiKey("work", ["meta/work"])).toBe(true);
346-
expect(metaOAuthSlugBlockedByApiKey("work", ["meta-api/work"])).toBe(false);
346+
expect(metaOAuthSlugBlockedByApiKey("work", ["meta-api/work"])).toBe(true);
347+
});
348+
349+
test("an existing Meta OAuth profile is not treated as an API key", () => {
350+
expect(metaOAuthSlugBlockedByApiKey("work", ["meta/work"], ["work"])).toBe(
351+
false,
352+
);
353+
expect(
354+
metaOAuthSlugBlockedByApiKey("work", [
355+
{ name: "meta/work", apiKey: "identity-token", metaProfile: "work" },
356+
]),
357+
).toBe(false);
358+
expect(
359+
metaOAuthSlugBlockedByApiKey("work", [
360+
{ name: "meta/work", apiKey: "LLM|pasted" },
361+
]),
362+
).toBe(true);
347363
});
348364

349365
test("the pick-list ends with custom and every known provider is launchable", () => {

‎src/tui/provider/oauth.ts‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,38 @@ export function suggestMetaOAuthProfileSlug(
9393
]);
9494
}
9595

96-
/** True when `slug` is already an API-key instance, not an OAuth profile. */
96+
/** True when `slug` names an API-key row, not an OAuth profile. */
9797
export function metaOAuthSlugBlockedByApiKey(
9898
slug: string,
99-
existingProviderNames: readonly string[],
99+
rows: readonly (
100+
| string
101+
| {
102+
readonly name: string;
103+
readonly apiKey?: string;
104+
readonly metaProfile?: string;
105+
}
106+
)[],
107+
authProfiles: readonly string[] = [],
100108
): boolean {
101-
return instanceSlugsForKind("meta", existingProviderNames).includes(slug);
109+
if (authProfiles.includes(slug)) return false;
110+
for (const row of rows) {
111+
if (typeof row !== "string" && row.metaProfile === slug) return false;
112+
}
113+
const names = rows.map((row) => (typeof row === "string" ? row : row.name));
114+
if (instanceSlugsForKind("meta-api", names).includes(slug)) return true;
115+
for (const row of rows) {
116+
const name = typeof row === "string" ? row : row.name;
117+
if (!instanceSlugsForKind("meta", [name]).includes(slug)) continue;
118+
if (typeof row !== "string" && row.metaProfile !== undefined) continue;
119+
if (
120+
typeof row !== "string" &&
121+
(typeof row.apiKey !== "string" || row.apiKey.length === 0)
122+
) {
123+
continue;
124+
}
125+
return true;
126+
}
127+
return false;
102128
}
103129

104130
/**
@@ -450,7 +476,7 @@ export function createAccountNameFlow(
450476
if (state.settled || attempt !== state.oauthNameAttempt) return;
451477
if (
452478
state.choice?.oauth === "meta" &&
453-
metaOAuthSlugBlockedByApiKey(slug, state.existingProviderNames)
479+
metaOAuthSlugBlockedByApiKey(slug, state.existingProviderNames, names)
454480
) {
455481
state.oauthProfileError = "that name is an API key";
456482
state.oauthProfileConfirmPending = false;

0 commit comments

Comments
 (0)