@@ -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. */
9797export 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