-
Notifications
You must be signed in to change notification settings - Fork 10
feat: allow 2-factor authentication #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| }); | ||
|
|
||
| return ig.account.login(answers.username, answers.password); | ||
| return Bluebird.try(() => ig.account.login(answers.username, answers.password)).catch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Bluebird really necessary for this ? A regular try/catch block should do the work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the code which is an example on the Instagram-private-api, but I didn't ask myself the question of whether Bluebird was really useful or not, I'm going to do some testing and see if it changes anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After re-examining the code, Bluebird is used to do try/catch with Promises so a classic try/catch block would not allow you to do that, especially since it catches the error in the catch but also a class "IgLoginTwoFactorRequiredError" which is used to type the error or something like that, from what I understood
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be strictly equivalent.
try {
// return await within an async makes the function try to resolve the promise, if not it will fall in the following catch block
return await ig.account.login(answers.username, answers.password)
} catch (err) {
// Only handle IgLoginTwoFactorRequiredError
if (!(err instanceof IgLoginTwoFactorRequiredError)) {
throw e; // Unhandled error
}
// err should now be inferred as IgLoginTwoFactorRequiredError
const { username, totp_two_factor_on, two_factor_identifier } = err.response.body.two_factor_info
const verificationMethod = totp_two_factor_on ? '0' : '1';
const { code } = await inquirer.prompt([
{
type: 'input',
name: 'code',
message: `Enter code received via ${verificationMethod === '1' ? 'SMS' : 'TOTP'}`,
},
]);
try {
// Same thing as above, try to resolve the promise.
return await ig.account.twoFactorLogin({
username,
verificationCode: code,
twoFactorIdentifier: two_factor_identifier,
verificationMethod, // '1' = SMS (default), '0' = TOTP (google auth for example)
trustThisDevice: '1', // Can be omitted as '1' is used by default
});
} catch (e) {
// Log the error. Ideally, it should be rethrown because catching without rethrowing makes the process run as if there was no error
console.error(e)
}
}Here is the complete explanation of return await https://stackoverflow.com/a/62819622/8886385
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so good, you found what was missing, will you update the github repo?
noook
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except for Bluebird I don't believe this dependency is necessary
No description provided.