@@ -162,10 +162,11 @@ export const OpenAIAuthPlugin: Plugin = async ({ client }: PluginInput) => {
162162 ) ;
163163 } ;
164164
165- const runOAuthFlow = async (
166- useManualMode : boolean ,
167- ) : Promise < TokenResult > => {
168- const { pkce, state, url } = await createAuthorizationFlow ( ) ;
165+ const runOAuthFlow = async (
166+ useManualMode : boolean ,
167+ forceNewLogin : boolean = false ,
168+ ) : Promise < TokenResult > => {
169+ const { pkce, state, url } = await createAuthorizationFlow ( { forceNewLogin } ) ;
169170 console . log ( "\nOAuth URL:\n" + url + "\n" ) ;
170171
171172 if ( useManualMode ) {
@@ -797,14 +798,40 @@ export const OpenAIAuthPlugin: Plugin = async ({ client }: PluginInput) => {
797798 }
798799 }
799800
800- while ( accounts . length < ACCOUNT_LIMITS . MAX_ACCOUNTS ) {
801- console . log (
802- `\n=== OpenAI OAuth (Account ${
803- accounts . length + 1
804- } ) ===`,
805- ) ;
806- const result = await runOAuthFlow ( useManualMode ) ;
807- if ( result . type === "failed" ) {
801+ while ( accounts . length < ACCOUNT_LIMITS . MAX_ACCOUNTS ) {
802+ console . log (
803+ `\n=== OpenAI OAuth (Account ${
804+ accounts . length + 1
805+ } ) ===`,
806+ ) ;
807+
808+ const forceNewLogin = accounts . length > 0 ;
809+ const result = await runOAuthFlow ( useManualMode , forceNewLogin ) ;
810+
811+ if ( result . type === "success" ) {
812+ const email = extractAccountEmail ( result . access ) ;
813+ const accountId = extractAccountId ( result . access ) ;
814+ const label = email || accountId || "Unknown account" ;
815+ console . log ( `\n✓ Authenticated as: ${ label } \n` ) ;
816+
817+ const isDuplicate = accounts . some (
818+ ( acc ) =>
819+ ( accountId && extractAccountId ( acc . access ) === accountId ) ||
820+ ( email && extractAccountEmail ( acc . access ) === email ) ,
821+ ) ;
822+
823+ if ( isDuplicate ) {
824+ console . warn (
825+ `\n⚠️ WARNING: You authenticated with an account that is already in the list (${ label } ).` ,
826+ ) ;
827+ console . warn (
828+ "This usually happens if you didn't log out or use a different browser profile." ,
829+ ) ;
830+ console . warn ( "The duplicate will update the existing entry.\n" ) ;
831+ }
832+ }
833+
834+ if ( result . type === "failed" ) {
808835 if ( accounts . length === 0 ) {
809836 return {
810837 url : "" ,
0 commit comments