From c36466faddda75dcbfcc7f1e18d275917e41e707 Mon Sep 17 00:00:00 2001 From: Edgard Date: Mon, 29 Mar 2021 23:42:23 -0300 Subject: [PATCH] fix: Fixed inject token for authentication --- src/controllers/auth.ts | 20 +++++++++++++++++--- src/lib/wapi/wapi.js | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/controllers/auth.ts b/src/controllers/auth.ts index cdddddb85..eddda16d4 100644 --- a/src/controllers/auth.ts +++ b/src/controllers/auth.ts @@ -23,6 +23,7 @@ import { existsSync, readFileSync } from 'fs'; import { CreateConfig } from '../config/create-config'; import { ScrapQrcode } from '../api/model/qrcode'; import { tokenSession } from '../config/tokenSession.config'; +import { puppeteerConfig } from '../config/puppeteer.config'; export const getInterfaceStatus = async ( waPage: puppeteer.Page @@ -183,14 +184,27 @@ export async function auth_InjectToken( return false; } - //Auth with token ->start<- - return await page.evaluateOnNewDocument((session) => { + await page.setRequestInterception(true); + const reqHandler = (req: puppeteer.Request) => { + req.respond({ + status: 200, + contentType: 'text/plain', + body: 'injecting token...', + }); + }; + page.on('request', reqHandler); + + await page.goto(puppeteerConfig.whatsappUrl); + await page.evaluate((session) => { localStorage.clear(); Object.keys(session).forEach((key) => { localStorage.setItem(key, session[key]); }); }, token as any); - //End Auth with token + + // Disable + page.off('request', reqHandler); + await page.setRequestInterception(false); } export async function saveToken( diff --git a/src/lib/wapi/wapi.js b/src/lib/wapi/wapi.js index 34b68fdb4..d200231e4 100644 --- a/src/lib/wapi/wapi.js +++ b/src/lib/wapi/wapi.js @@ -157,7 +157,8 @@ if (typeof window.Store === 'undefined') { for (const store of storeObjects) { window.Store.promises[store.id] = loader - .waitForModule(store.conditions) + .waitForModule((m) => !!store.conditions(m)) + .then(store.conditions) .then((m) => { if (store.id === 'Store') { window.Store = Object.assign({}, window.Store, m);