Skip to content

Commit 160bc3a

Browse files
committed
🐛 Login correctly handles error when credentials are invalid
1 parent 8340fbd commit 160bc3a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "igdm",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Send and receive Instagram direct message through CLI.",
55
"keywords": [
66
"instagram",

src/domain/auth.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import chalk from 'chalk';
77
const prefix = chalk.blue('?');
88

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

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

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

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

@@ -73,8 +73,10 @@ export default class Authenticator {
7373
})
7474
.then(() => ig)
7575
.catch(() => {
76+
const error = chalk.red.bold('An error occurred while logging in. Check your credentials or your network connectivity.');
77+
console.error(error);
7678
this.logout();
77-
throw new Error('An error occurred while logging in.');
79+
throw new Error(error)
7880
});
7981
}
8082

0 commit comments

Comments
 (0)