MCPcopy Create free account
hub / github.com/MuYunyun/create-react-doc / login

Function login

packages/leetcode-cli/src/leetcode.js:26–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24const graphqlUrl = `${baseUrl}/graphql`
25
26const login = async () => {
27 let loginUrl = baseUrl
28 if (country === undefined) {
29 loginUrl = (
30 await inquirer.prompt({
31 name: 'baseUrl',
32 type: 'list',
33 message: 'Log in to:',
34 choices: [usUrl, cnUrl],
35 })
36 ).baseUrl
37 setConfig({ country: loginUrl === cnUrl ? 'cn' : 'us' })
38 }
39 loginUrl += '/accounts/login/'
40
41 const spinner = ora('Login...').start()
42 try {
43 // it have to set executablePath or it'll be broken.https://github.com/puppeteer/puppeteer/issues/6425
44 // temporary way: https://stackoverflow.com/questions/47122579/run-puppeteer-on-already-installed-chrome-on-macos
45 const browser = await puppeteer.launch({ headless: false, executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' })
46 const page = await browser.newPage()
47 await page.goto(loginUrl)
48 await page.waitForFunction('window.location.href.indexOf("login") === -1')
49 let cookies = await page.cookies()
50 await browser.close()
51 spinner.stop()
52 cookies = cookies.reduce((acc, cookie) => {
53 const { name } = cookie
54 acc[name] = cookie
55 return acc
56 }, {})
57 setConfig({ cookies })
58 return cookies
59 } catch (error) {
60 console.error('Login failure, retry...', error.message)
61 throw error
62 } finally {
63 spinner.stop()
64 }
65}
66
67const getCookie = async () => {
68 // eslint-disable-line

Callers 1

getCookieFunction · 0.85

Calls 1

setConfigFunction · 0.85

Tested by

no test coverage detected