Skip to content

Commit 41c2f5c

Browse files
committed
fix(instagram-api): re-prompt via requestInput on invalid env credentials
When env-provided credentials (PLATFORM_LOGIN / PLATFORM_PASSWORD) fail with invalid_credentials, fall through to the existing promptWithRetry loop instead of throwing immediately. Matches the no-env path behavior and supports the bad-password canary mode in context-gateway. Other error kinds (login_api_error, network, etc.) still throw as before. Real users who fat-finger their password now re-prompt instead of seeing a generic failure. Ported from an ad-hoc snapshot edit in context-gateway PR #185.
1 parent fa12b74 commit 41c2f5c

1 file changed

Lines changed: 42 additions & 33 deletions

File tree

connectors/meta/instagram-api-playwright.js

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -771,43 +771,24 @@ const performLogin = async () => {
771771
});
772772
};
773773

774-
let result;
775-
if (PLATFORM_LOGIN && PLATFORM_PASSWORD) {
776-
result = await submitCredentials(1, 'env');
777-
if (result.kind === 'error') {
778-
const message = result.message || 'unknown reason';
779-
await setAuthState(
780-
await buildAuthState(
781-
isInvalidCredentialMessage(message)
782-
? 'invalid_credentials'
783-
: 'login_api_error',
784-
{
785-
attempt: 1,
786-
apiMessage: message,
787-
credentialSource: 'env',
788-
},
789-
),
790-
);
791-
throw new Error('Instagram login failed: ' + message);
792-
}
793-
} else {
794-
const buildCredsSpec = () => ({
795-
message: 'Log in to Instagram',
796-
schema: {
797-
type: 'object',
798-
properties: {
799-
username: {
800-
type: 'string',
801-
title: 'Instagram username, email, or phone',
802-
},
803-
password: { type: 'string', format: 'password', title: 'Password' },
774+
const buildCredsSpec = () => ({
775+
message: 'Log in to Instagram',
776+
schema: {
777+
type: 'object',
778+
properties: {
779+
username: {
780+
type: 'string',
781+
title: 'Instagram username, email, or phone',
804782
},
805-
required: ['username', 'password'],
783+
password: { type: 'string', format: 'password', title: 'Password' },
806784
},
807-
});
785+
required: ['username', 'password'],
786+
},
787+
});
808788

789+
const runCredentialPromptLoop = async () => {
809790
try {
810-
result = await promptWithRetry(buildCredsSpec, async (creds, attemptIndex) => {
791+
return await promptWithRetry(buildCredsSpec, async (creds, attemptIndex) => {
811792
const attempt = attemptIndex + 1;
812793
PLATFORM_LOGIN = String(creds.username || '').trim();
813794
PLATFORM_PASSWORD = String(creds.password || '');
@@ -846,6 +827,34 @@ const performLogin = async () => {
846827
}
847828
throw e;
848829
}
830+
};
831+
832+
let result;
833+
if (PLATFORM_LOGIN && PLATFORM_PASSWORD) {
834+
result = await submitCredentials(1, 'env');
835+
if (result.kind === 'error') {
836+
const message = result.message || 'unknown reason';
837+
const isInvalidCreds = isInvalidCredentialMessage(message);
838+
await setAuthState(
839+
await buildAuthState(
840+
isInvalidCreds ? 'invalid_credentials' : 'login_api_error',
841+
{
842+
attempt: 1,
843+
apiMessage: message,
844+
credentialSource: 'env',
845+
},
846+
),
847+
);
848+
if (isInvalidCreds) {
849+
// Env credentials were wrong — fall through to prompt the user
850+
// (supports bad-password canary mode and real-user fat-finger).
851+
result = await runCredentialPromptLoop();
852+
} else {
853+
throw new Error('Instagram login failed: ' + message);
854+
}
855+
}
856+
} else {
857+
result = await runCredentialPromptLoop();
849858
}
850859

851860
if (result.kind === 'ok') {

0 commit comments

Comments
 (0)