Skip to content

Commit

Permalink
fix: token
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Mar 31, 2021
1 parent 074dc28 commit b75c51a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/api/layers/host.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import { scrapeImg } from '../helpers';
import {
asciiQr,
isAuthenticated,
isInsideChat,
isInsideChats,
needsToScan,
retrieveQR,
} from '../../controllers/auth';
Expand Down Expand Up @@ -235,11 +235,11 @@ export class HostLayer {
}

public async waitForInChat() {
let inChat = await isInsideChat(this.page);
let inChat = await isInsideChats(this.page);

while (inChat === false) {
await sleep(200);
inChat = await isInsideChat(this.page);
inChat = await isInsideChats(this.page);
}
return inChat;
}
Expand All @@ -262,8 +262,17 @@ export class HostLayer {
.catch(() => {});

this.spin('Checking is logged...');

let authenticated = await isAuthenticated(this.page).catch(() => null);

if (typeof authenticated === 'object') {
this.spin(`Error http: ${authenticated.type}`, 'fail');
this.page.close();
throw `Error http: ${authenticated.type}`;
}

this.startAutoClose();

if (authenticated === false) {
this.spin('Waiting for QRCode Scan...');
statusFind && statusFind('notLogged', this.session);
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ export async function initWhatsapp(
): Promise<Page> {
const waPage: Page = await getWhatsappPage(browser);
if (waPage != null) {
// Auth with token
await auth_InjectToken(waPage, session, options, token);
await waPage.setUserAgent(useragentOverride);

const timeout = 2 * 1000;
await Promise.race([
waPage.goto(puppeteerConfig.whatsappUrl, { timeout }).catch(() => {}),
waPage.waitForSelector('body', { timeout }).catch(() => {}),
]);
// Auth with token
await auth_InjectToken(waPage, session, options, token);
return waPage;
}
}
Expand Down

1 comment on commit b75c51a

@jonalan7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.