Skip to content

Commit

Permalink
🐛 Login correctly handles error when credentials are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
noook committed May 9, 2021
1 parent 8340fbd commit 160bc3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "igdm",
"version": "1.3.2",
"version": "1.3.3",
"description": "Send and receive Instagram direct message through CLI.",
"keywords": [
"instagram",
Expand Down
8 changes: 5 additions & 3 deletions src/domain/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import chalk from 'chalk';
const prefix = chalk.blue('?');

export default class Authenticator {
private sessionPath: string = resolve(process.mainModule!.path, '..', 'session.json')
private sessionPath: string = resolve(require.main!.path, '..', 'session.json')

private saveSession(data: object) {
writeFileSync(this.sessionPath, JSON.stringify(data));
}

private get sessionExists(): boolean {
const session = readFileSync(this.sessionPath, { encoding: 'utf-8' });
if (JSON.stringify(session) === '"{}"') return false;
if (session === '{}') return false;

const cookies: { cookies: { key: string }[] } = JSON.parse(this.loadSession().cookies);

Expand Down Expand Up @@ -73,8 +73,10 @@ export default class Authenticator {
})
.then(() => ig)
.catch(() => {
const error = chalk.red.bold('An error occurred while logging in. Check your credentials or your network connectivity.');
console.error(error);
this.logout();
throw new Error('An error occurred while logging in.');
throw new Error(error)
});
}

Expand Down

0 comments on commit 160bc3a

Please sign in to comment.