Skip to content

Commit

Permalink
fix: Fixed inject token for authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Mar 30, 2021
1 parent 0cdbf81 commit c36466f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c36466f

Please sign in to comment.