Skip to content

Commit 5dad446

Browse files
committed
Adding a isGoogleLogin flag to getOpenAIAuth so users with a google account can authenticate that way.
1 parent c936391 commit 5dad446

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/openai-auth.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ export async function getOpenAIAuth({
4040
email,
4141
password,
4242
timeoutMs = 2 * 60 * 1000,
43-
browser
43+
browser,
44+
isGoogleLogin
4445
}: {
4546
email?: string
4647
password?: string
4748
timeoutMs?: number
4849
browser?: Browser
50+
isGoogleLogin?: boolean
4951
}): Promise<OpenAIAuth> {
5052
let page: Page
5153
let origBrowser = browser
@@ -76,17 +78,34 @@ export async function getOpenAIAuth({
7678
waitUntil: 'networkidle0'
7779
})
7880
])
79-
await page.waitForSelector('#username')
80-
await page.type('#username', email, { delay: 10 })
81-
await page.click('button[type="submit"]')
82-
await page.waitForSelector('#password')
83-
await page.type('#password', password, { delay: 10 })
84-
await Promise.all([
85-
page.click('button[type="submit"]'),
86-
page.waitForNavigation({
87-
waitUntil: 'networkidle0'
88-
})
89-
])
81+
if (isGoogleLogin) {
82+
await page.click('button[data-provider="google"]')
83+
await page.waitForSelector('input[type="email"]')
84+
await page.type('input[type="email"]', email, { delay: 10 })
85+
await Promise.all([
86+
page.waitForNavigation(),
87+
await page.keyboard.press('Enter')
88+
])
89+
await page.waitForSelector('input[type="password"]', { visible: true })
90+
await page.type('input[type="password"]', password, { delay: 10 })
91+
await page.keyboard.press('Enter')
92+
await Promise.all([
93+
page.waitForNavigation({
94+
waitUntil: 'networkidle0'
95+
})
96+
])
97+
} else {
98+
await page.type('#username', email, { delay: 10 })
99+
await page.click('button[type="submit"]')
100+
await page.waitForSelector('#password')
101+
await page.type('#password', password, { delay: 10 })
102+
await Promise.all([
103+
page.click('button[type="submit"]'),
104+
page.waitForNavigation({
105+
waitUntil: 'networkidle0'
106+
})
107+
])
108+
}
90109
}
91110

92111
const pageCookies = await page.cookies()

0 commit comments

Comments
 (0)