This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tktrex): defined hook for login
- Loading branch information
1 parent
835310d
commit 0b04327
Showing
5 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
platforms/tktrex/shared/src/methodology/directives/tiktokLogin.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { HookHandler } from '@shared/providers/puppeteer/DirectiveHook'; | ||
import { sleep } from '@shared/utils/promise.utils'; | ||
import * as qs from 'qs'; | ||
import { URL } from 'url'; | ||
|
||
interface TKLoginContext { | ||
getUsername: () => Promise<string>; | ||
getPassword: () => Promise<string>; | ||
} | ||
|
||
export const tkLogin = | ||
(ctx: TKLoginContext): HookHandler => | ||
async (page, directive, opts) => { | ||
const url = page.url(); | ||
const search = qs.parse(new URL(url).search); | ||
const redirectUrl = search.redirect_url as string; | ||
await page.goto('https://www.tiktok.com/login'); | ||
|
||
const loginButton = await page.waitForSelector( | ||
'[class*="login-container"] > [class*="social-container"] > [class*="channel-item-wrapper"]:nth-of-type(2)' | ||
); | ||
|
||
await loginButton?.click(); | ||
|
||
const loginWithEmailButton = await page.waitForSelector( | ||
'a[href="/login/phone-or-email/email"]' | ||
); | ||
|
||
await loginWithEmailButton?.click(); | ||
|
||
const username = await ctx.getUsername(); | ||
await page.type('input[name="email"]', username); | ||
|
||
const password = await ctx.getPassword(); | ||
await page.type('input[name="password"]', password); | ||
|
||
await sleep(10000); | ||
|
||
const submitButton = await page.waitForSelector( | ||
'button[class*="login-button"]:not(disabled)', | ||
{ | ||
timeout: 10000, | ||
} | ||
); | ||
|
||
await submitButton?.click(); | ||
|
||
await page.goto(redirectUrl); | ||
|
||
return Promise.resolve(undefined); | ||
}; |