vscode-leetcode: Failed to log in with a leetcode.com account

🐛 Bug Report

I can’t log into my leetcode.com account via vscode plugin, but I can log in with the same email & password in the browser. In contrast, my leetcode-cn.com account seems to work fine with this vscode plugin.

To Reproduce

None

Expected behavior

Log into my leetcode.com account.

Extension Output

login:  Active  Name               Version         Desc
----------------------------------------------------------------------------------------------------
   ✔     solution.discuss   2019.02.03      Plugin to fetch most voted solution in discussions.
   ✔     company            2017.12.18      Plugin to query by company for free user.
   ✔     cache              default         Plugin to provide local cache.
   ✔     retry              default         Plugin to retry last failed request if autologin.enable is on.
   ✘     leetcode.cn        2018.11.25      Plugin to talk with leetcode-cn APIs.
   ✔     leetcode           default         Plugin to talk with leetcode APIs.
[ERROR] You are not login yet?
login: pass: - Signing in leetcode.com
[ERROR] invalid password?

Your Environment

  • os: Windows 10 Family Edition x64 (#18362)
  • extension settings: default
  • nodejs version: 12.4.0
  • vscode version: 1.40.1
  • extension version: 0.15.7

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 55
  • Comments: 261 (47 by maintainers)

Most upvoted comments

Any step-by-step instructions to solve the problem temporily ? thanks!

Spent an hour and figured it out. Here are the step by step instructions by people newbie like me.

  1. Make sure Node.js 8+ is installed. Instructions can be found on the official page

  2. Install leetcode-cli from OS terminal or the terminal within vscode. Installation guide. Note the “From Github” section links to an older version.

# to remove the old version
npm uninstall -g leetcode-cli
# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

Type leetcode version in terminal to make sure you installed version 2.6.17+.

  1. Log into leetcode.com in a browser. In Chrome, right click and select “Inspect”. Switch to tab “Network”, “XHR”. Then click any button on leetcode.com(now should be on the left split screen). Now you should be able to see the cookie as @yihong0618 showed in the pic. Copy the entire cookie string starting from “__cfduid” and ending with “_gat=1”

  2. Type leetcode user -c from terminal within vscode. Follow the prompt and type in your username and cookie you copied above.

Just to confirm what worked for me, thanks to whoever posted the solution.

  1. Login to leetcode
  2. Open Chrome inspector -> Network -> Fetch/XHR.
  3. Click on some button in leetcode page, and in Inspector to the right under the “Name” tab find and select bottom “graphql” (that worked for me) and under Headers tab and in “Request Headers” portion, select and copy that whole massive cookie string.
  4. That’s the cookie that got me in.

@jdneo @lostindark

  1. I had tried to use puppeteer but using puppeteer will cause a rotbot check problem.
  2. And the sencond way I also do my best to try but faild, and I happend to find that leetcode is beta their app, maybe we can try to get some luck

@jdneo

  1. I have try to session login that user can copy the cookie from chrome(or others) then paste to the vscode input field, one time login then all the others features are not affected so the user can use vscode-leetcode as usual, can I compelete it and pull request for short-term solution ?

The demo will be like below (user can only copy the cookie and vscode-cli will parser it ): image

image

This cookie but need to add some guide。 image


It works for me, thanks! To be more clear, the cookie is the entire String marked in Red in the pic.

leetcode

Then, In leetcode VS Code, Ctrl + Shift + P, choose, log in with cookie. Your Username, The copied Cookies. Enter!

if anyone encounter this issue, you can try to login use cookie

  1. first select the last option [login via cookie]

  2. login in your leetcode account in any browser

  3. open the developer tool of your browser, select [network] tab

  4. click on any request that has header, copy the cookie in the header Screen Shot 2022-05-10 at 11 48 42

  5. back to vscode, input your username,press [enter], then paste the cookie from step 4, then submit

and you will login in your account successfully. 😃

@jdneo @lostindark

  1. I had tried to use puppeteer but using puppeteer will cause a rotbot check problem.
  2. And the sencond way I also do my best to try but faild, and I happend to find that leetcode is beta their app, maybe we can try to get some luck

@jdneo

  1. I have try to session login that user can copy the cookie from chrome(or others) then paste to the vscode input field, one time login then all the others features are not affected so the user can use vscode-leetcode as usual, can I compelete it and pull request for short-term solution ?

The demo will be like below (user can only copy the cookie and vscode-cli will parser it ): image

image

This cookie but need to add some guide。 image

Just to confirm what worked for me, thanks to whoever posted the solution.

  1. Login to leetcode
  2. Open Chrome inspector -> Network -> Fetch/XHR.
  3. Click on some button in leetcode page, and in Inspector to the right under the “Name” tab find and select bottom “graphql” (that worked for me) and under Headers tab and in “Request Headers” portion, select and copy that whole massive cookie string.
  4. That’s the cookie that got me in.

My hero 😍

if anyone encounter this issue, you can try to login use cookie

  1. first select the last option [login via cookie]
  2. login in your leetcode account in any browser
  3. open the developer tool of your browser, select [network] tab
  4. click on any request that has header, copy the cookie in the header Screen Shot 2022-05-10 at 11 48 42
  5. back to vscode, input your username,press [enter], then paste the cookie from step 4, then submit

and you will login in your account successfully. 😃

Thank you so much. It is working perfectly. 😃

If you use chromium-based browsers there’s this extension I made that you can use to copy cookies: https://chromewebstore.google.com/detail/vsleet/ihgifhobfmjhcelknpbjhpabkcghjmfh?hl=en

Seems the same prblems. I try to locate it, one may cause the problem is that the leetcode.com use the recaptcha_token for now. And the code in leetcode-cli doesn’t have it. 222

But the leetcode-cn’s payload is as usual. image

And the leetcode-cli’s login payload is like below. image

I think may use another way to login and get the session or solve the recaptcha.

@jdneo @queensferryme

This worked for me…

  1. Use node --version of 12.0.0

npm install -g n

sudo n 12.0.0

  1. Install leetcode

npm install -g leetcode-cli

  1. Point the leetcode plugin to the correct node version:

image

  1. do this in order to configure the creds for your leetcode-cli session

  2. Check that your session is working via leetcode session, which should look like:

 Active    Id               Name                 AC Questions       AC Submits
--------------------------------------------------------------------------------
   ✔    1234567   Anonymous Session              12 ( 99.99 %)     12 ( 99.99 %)

=================================================

The below cookie method no longer works but is kept for posterity

3) Get Cookie Value

Open Chrome (must be Chrome, not Firefox) and go to https://leetcode.com/problemset/all/ (login if not already)

Navigate to View > Web Developer > Network, then filter for XHR request of all/ and copy the cookie value:

image

The cookie should start with __cfduid= and end with _gat=1

4) Load Cookie Value

leetcode user -c

<enter your email address>

<paste the cookie value>

You should see output of Successfully cookie login as <username>

@saksham1211 Did you find a solution somehow? I have the same issue with you and none of the above solutions works. BTW, I am on macOS Monterey. Can anyone help, please? Thank you so much

On macOS Monterey using Safari ⬇️

  1. Login Leetcode (US).
  2. Right Click, select inspect element (“Show Dev Menu in menu bar” must be enabled)
  3. Click on Leetcode Logo on website header.
  4. Select “Network” tab, followed by XHR/Fetch.
  5. Select “graphql” on left, under “Header Request” copy entire cookie string.

In VScode 😎

  1. Open new terminal.
  2. Type “leetcode user -c”
  3. Type Username, hit return, then paste the cookie when prompted, hit return.
  4. Quit VScode, re-open application. Screen Shot 2022-02-20 at 12 39 54 PM

1、找到leetcode插件位置,打开leetcode.js,找到这个位置 image 2、在网页上登录https://leetcode-cn.com/,登录成功之后F12, image copy LEETCODE_SESSION和csrftoken,注意对应 3、修改leetcode.js上面的代码 image

然后保存,之后在vscode登录leetcode, 选择直接登录,账号密码随便输入就行

Can not login with cookies.

cookie: - Retrieving user favorites
[WARN] Failed to retrieve user favorites: [object Object]
- Retrieving user profile
/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55
      let s = args.map(x => x.toString()).join(' ');
                              ^

TypeError: Cannot read properties of undefined (reading 'toString')
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:31
    at Array.map (<anonymous>)
    at log.<computed> [as info] (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:20)
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/commands/user.js:121:13
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:523:14
    at Request._callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:422:19)
    at self.callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:185:22)
    at Request.emit (node:events:514:28)
    at Request.<anonymous> (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:1161:10)
    at Request.emit (node:events:514:28)

Node.js v20.10.0

Same here. It was working till afternoon, but suddenly stopped working from evening. Please let me know if you were able to find a workaround.

I’m having the same difficulties, but it’s working again as of right now

same

same question. It worked yesterday, but not today

Hi, Does any of the solution working for anyone? I tried all of the above suggested solutions, none of them worked for me. Any help would be appreciated.

Thanks

@saksham1211 I have a leetcode.com account that just uses my email (not 3rd party) and the cookie method works for me currently. While the cookie looks quite different, it still works.

leet-cookie

You have to copy the entire cookie string.

It turns out that the cookies that we get from the website has changed its format:

image

And now I have

image

@Cering There are two steps to get the cookie

  1. Login
  2. Call any api (such as click the problems button) not only get the leetcode session but also you need to get the csrf token. Because you have no csrf token you can only get the problems and your profile. As below: image

I found a workaround works for me.

I’ve noticed vscode-leetcode now utilizes vsc-leetcode-cli which only parses and uses ‘LEETCODE_SESSION’ and ‘csrftoken’ from the input cookie string when we login with the ‘Leetcode Cookie’ option. image

So i just input a minimum custom cookie string to login like: “LEETCODE_SESSION=xxxxxxxxx;csrftoken=xxxxx;”,and we can find the values of ‘LEETCODE_SESSION’ and ‘csrftoken’ in the storage cookies under the ‘Application’ tab of the browser dev tools when we use our browser to vist leetcode.com. image

Try the realname in the ‘Response’ for username of login and whole cookie, it work for me. image image

Oh, As I directly copy all of the content in “all/” tag, it works. Screen Shot 2020-12-24 at 3 28 36 PM

For ppl tried all the above suggestions but still failed:

I tried to get the cookies (graphql, non graphql starting with “_ga” and other solutions) from Firefox and kept getting either “cb” error or “x.toString()” error, and none of the above resolves my issue. Until I switched to Chrome to get the cookie and succeeded with graphql request cookie value. (something starts with “gr_user_id=”)

switch to leetcode-cn.com and you can use it

image i want use github account number to sign in but in vain, lord help me , i want to study

Can not login with cookies.

cookie: - Retrieving user favorites
[WARN] Failed to retrieve user favorites: [object Object]
- Retrieving user profile
/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55
      let s = args.map(x => x.toString()).join(' ');
                              ^

TypeError: Cannot read properties of undefined (reading 'toString')
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:31
    at Array.map (<anonymous>)
    at log.<computed> [as info] (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:20)
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/commands/user.js:121:13
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:523:14
    at Request._callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:422:19)
    at self.callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:185:22)
    at Request.emit (node:events:514:28)
    at Request.<anonymous> (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:1161:10)
    at Request.emit (node:events:514:28)

Node.js v20.10.0

I found a workaround works for me. I’ve noticed vscode-leetcode now utilizes vsc-leetcode-cli which only parses and uses ‘LEETCODE_SESSION’ and ‘csrftoken’ from the input cookie string when we login with the ‘Leetcode Cookie’ option. image So i just input a minimum custom cookie string to login like: “LEETCODE_SESSION=xxxxxxxxx;csrftoken=xxxxx;”,and we can find the values of ‘LEETCODE_SESSION’ and ‘csrftoken’ in the storage cookies under the ‘Application’ tab of the browser dev tools when we use our browser to vist leetcode.com. image

Hi, I also have this problem. could you give a more detail method?

Refresh the page. Go to the networks tab in developer options. Select Fetch/XHR. Under the names sections, select any graphql req/res. Go to the request headers section. Locate the cookie key there. Select only this part of the cookie value -> csrftoken=“xyz”; LEETCODE_SESSION=“xyz”; Open terminal, type leetcode user -c Enter username and this cookie value.

if anyone encounter this issue, you can try to login use cookie

  1. first select the last option [login via cookie]
  2. login in your leetcode account in any browser
  3. open the developer tool of your browser, select [network] tab
  4. click on any request that has header, copy the cookie in the header Screen Shot 2022-05-10 at 11 48 42
  5. back to vscode, input your username,press [enter], then paste the cookie from step 4, then submit

and you will login in your account successfully. 😃

thank you so much, got it working now 😃

The prompt doesn’t clarify what format do we need to input. There’s no field starting with “__cfduid” or with “_gat=1” in the cookie these days.

Wasting 10 minutes browsing the post and finally I found the answer: cookies with the format of semicolon separated pairs. (You need all the cookies, not a single field)

Fuck leetcode-cli, you don’t want it. Install EditThisCookie extension and change the export format and export the cookie. That’s it.

  1. you must login on the chrome or something else.
  2. click one link that you can find the cookie in xhr I clicked the all problems
  3. copy the cookie(the whole content) which is mine below

image

We now support Cookie login, third-party login (GitHub, LinkedIn)

This problem should be mitigated now.

Just to confirm what worked for me, thanks to whoever posted the solution.

  1. Login to leetcode
  2. Open Chrome inspector -> Network -> Fetch/XHR.
  3. Click on some button in leetcode page, and in Inspector to the right under the “Name” tab find and select bottom “graphql” (that worked for me) and under Headers tab and in “Request Headers” portion, select and copy that whole massive cookie string.
  4. That’s the cookie that got me in.

This works, thanks.

Yeah boy

你好,邮件收到了,会尽快回复。

Just to confirm what worked for me, thanks to whoever posted the solution.

  1. Login to leetcode
  2. Open Chrome inspector -> Network -> Fetch/XHR.
  3. Click on some button in leetcode page, and in Inspector to the right under the “Name” tab find and select bottom “graphql” (that worked for me) and under Headers tab and in “Request Headers” portion, select and copy that whole massive cookie string.
  4. That’s the cookie that got me in.

This works, thanks.

@LifeOfJona

  1. Please check your vscode-leetcode is the latest version and reload it
  2. Type" Command + Shift + p or F1" then vscode will pop up an input
  3. Then type “Sign In by Cookie” you may see somthing like below image
  4. Enter and maybe wait a little seconds (vscode-leetcode will load data) then type your account image
  5. Paste your cookie from chrome or other
  6. Type Enter and wait for below image

@zhoujf620 There’s no need to paste cookies to json

You can follow the steps

  1. Update vscode-leetcode to the lastest version

  2. Reload the vscode-leetcode

  3. Command “ctrl + shift +p”(if mac “command + shift + p”) then type leetcode sign in by cookie

  4. Type click enter button May like this image

Can not login with cookies.

cookie: - Retrieving user favorites
[WARN] Failed to retrieve user favorites: [object Object]
- Retrieving user profile
/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55
      let s = args.map(x => x.toString()).join(' ');
                              ^

TypeError: Cannot read properties of undefined (reading 'toString')
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:31
    at Array.map (<anonymous>)
    at log.<computed> [as info] (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:20)
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/commands/user.js:121:13
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:523:14
    at Request._callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:422:19)
    at self.callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:185:22)
    at Request.emit (node:events:514:28)
    at Request.<anonymous> (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:1161:10)
    at Request.emit (node:events:514:28)

Node.js v20.10.0

Same here. It was working till afternoon, but suddenly stopped working from evening. Please let me know if you were able to find a workaround.

I’m having the same difficulties, but it’s working again as of right now

same

If you use chromium-based browsers there’s this extension I made that you can use to copy cookies: https://chromewebstore.google.com/detail/vsleet/ihgifhobfmjhcelknpbjhpabkcghjmfh?hl=en

https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/478#issuecomment-1786257954

It works, thanks! I still don’t understand why it gets the different cookies than I get from browser developer mode. But the cookies it gets works fine and I logged in in VS-code smoothly.

image

《csrftoken=“xyz”; LEETCODE_SESSION=“xyz”;》 Can solve this problem

Hey, I am not able to log in using any of the method provided here. I did all what the people on this thread suggested but failed to log into my account. 😦

image

Got this error. Anyone found any solutions?

Any step-by-step instructions to solve the problem temporily ? thanks!

Spent an hour and figured it out. Here are the step by step instructions by people newbie like me.

  1. Make sure Node.js 8+ is installed. Instructions can be found on the official page
  2. Install leetcode-cli from OS terminal or the terminal within vscode. Installation guide. Note the “From Github” section links to an older version.
# to remove the old version
npm uninstall -g leetcode-cli
# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

Type leetcode version in terminal to make sure you installed version 2.6.17+.

  1. Log into leetcode.com in a browser. In Chrome, right click and select “Inspect”. Switch to tab “Network”, “XHR”. Then click any button on leetcode.com(now should be on the left split screen). Now you should be able to see the cookie as @yihong0618 showed in the pic. Copy the entire cookie string starting from “__cfduid” and ending with “_gat=1”
  2. Type leetcode user -c from terminal within vscode. Follow the prompt and type in your username and cookie you copied above.

today(2021/6/4) this solution is not work.

Still facing this error. With cookies it fails with TypeError: Cannot read property 'isCurrentUserPremium' of null Doesnt login with github because of TFA and linkedin too.

@victor886 the solution is not simple. Maybe you can wait for @jdneo’s update. I think the best way for now is using leetcode-cn (you can trans your data from leetcode.com), the leetcode-cn works well. And because of our “GFW”, I think they will not add recaptcha so soon(need google api). And I just add “user -c” method in leetcode-cli you can also use that. You can login leetcode with chrome and press F12, click->network->XHR and you could see your cookie as below image

can’t login leetcode version 2.8.0

/Users/admin/.nvm/versions/node/v14.15.1/lib/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:519
        user.paid = _user.isCurrentUserPremium;
                          ^

TypeError: Cannot read property 'isCurrentUserPremium' of null
    at /Users/admin/.nvm/versions/node/v14.15.1/lib/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:519:27
    at Request._callback (/Users/admin/.nvm/versions/node/v14.15.1/lib/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:425:12)
    at Request.self.callback (/Users/admin/.nvm/versions/node/v14.15.1/lib/node_modules/vsc-leetcode-cli/node_modules/request/request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.<anonymous> (/Users/admin/.nvm/versions/node/v14.15.1/lib/node_modules/vsc-leetcode-cli/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:315:20)
    at IncomingMessage.<anonymous> (/Users/admin/.nvm/versions/node/v14.15.1/lib/node_modules/vsc-leetcode-cli/node_modules/request/request.js:1083:12)

was having this problem but this solution worked

image

《csrftoken=“xyz”; LEETCODE_SESSION=“xyz”;》 Can solve this problem

just copy and paste csrftoken=“xyz”; LEETCODE_SESSION=“xyz”; somewhere else then go grab the two cookie values and replace xyz with them. after that copy the entire thing and use it as cookie login

I found a workaround works for me. I’ve noticed vscode-leetcode now utilizes vsc-leetcode-cli which only parses and uses ‘LEETCODE_SESSION’ and ‘csrftoken’ from the input cookie string when we login with the ‘Leetcode Cookie’ option. image So i just input a minimum custom cookie string to login like: “LEETCODE_SESSION=xxxxxxxxx;csrftoken=xxxxx;”,and we can find the values of ‘LEETCODE_SESSION’ and ‘csrftoken’ in the storage cookies under the ‘Application’ tab of the browser dev tools when we use our browser to vist leetcode.com. image

Hi, I also have this problem. could you give a more detail method?

Refresh the page. Go to the networks tab in developer options. Select Fetch/XHR. Under the names sections, select any graphql req/res. Go to the request headers section. Locate the cookie key there. Select only this part of the cookie value -> csrftoken=“xyz”; LEETCODE_SESSION=“xyz”; Open terminal, type leetcode user -c Enter username and this cookie value.

this works for me. thanks

Thanks this worked for me via a extra step so anyone can try this, follow the above things and after leetcode user -c command, enter then write like username csrftoken=“xyz”; LEETCODE_SESSION=“xyz”; After this it asked me for cookie again then write the same thing again and it will work.

I don’t want to, but I can’t log in by changing to cn…

login: pass: - Signing in leetcode-cn.com
[ERROR] invalid password?
    return cb('invalid cookie?');
           ^
TypeError: cb is not a function

There is no change in the extension sleeve code of the vscode, and is there no progress on the issue now? 😞

image My LeetCode uninstalled once and I couldn’t log in ,my version is 0.17.0 node js s version is 15.50, vscode 1.52.1 thanks

@yhnedison

  1. make sure you have installed latest version leetcode-cli which is 2.6.17
  2. check the plugin point that you are using leetcode not leetcode.cn
  3. cli: leetcode-cli user -L (big L) to logout Delete default plugin from leetcode.cn cli: leetcode-cli plugin -d leetcode.cn(delete leetcode.cn) Change default to leetcode cli: leetcode-cli plugin -e leetcode

  4. leetcode-cli user -c

Thank you! It’s working now!

For anyone wondering, please use https://github.com/leetcode-tools/leetcode-cli (instead of https://github.com/skygragon/leetcode-cli) and build from source to get 2.6.17 and follow the steps above.

After adding some logs, it seems that the login requests are blocked by Cloudflare’s JS Challenge. Have tried changing IPs and adding headers like User-Agent, but still not working. Perhaps it’s related to some Cloudflare specified cookies to check if the request is from a browser or a script, not sure what to do next.

Can not login with cookies.无法使用cookie登录。

cookie: - Retrieving user favorites
[WARN] Failed to retrieve user favorites: [object Object]
- Retrieving user profile
/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55
      let s = args.map(x => x.toString()).join(' ');
                              ^

TypeError: Cannot read properties of undefined (reading 'toString')
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:31
    at Array.map (<anonymous>)
    at log.<computed> [as info] (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/log.js:55:20)
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/commands/user.js:121:13
    at /Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:523:14
    at Request._callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:422:19)
    at self.callback (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:185:22)
    at Request.emit (node:events:514:28)
    at Request.<anonymous> (/Users/soulike/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/request/request.js:1161:10)
    at Request.emit (node:events:514:28)

Node.js v20.10.0

Same here. It was working till afternoon, but suddenly stopped working from evening. Please let me know if you were able to find a workaround.同样在这里。它一直工作到下午,但从晚上突然停止工作。如果您能够找到解决方法,请告诉我。

I’m having the same difficulties, but it’s working again as of right now我遇到了同样的困难,但截至目前,它又开始工作了

same 相同

same question, it was working fine in yesterday, but when I try to use this plugin today, it just cannot login.

it’s still not working , i tried it with my email and the cookie with the format of: csrftoken=“xyz”;LEETCODE_SESSION=“xyz”;

user.paid = _user.isCurrentUserPremium; 
                         
TypeError: Cannot read properties of null (reading 'isCurrentUserPremium')

+1

I was able to use the Cookie way to log in.

I don’t know why it’s not working last time. But this morning I tried it with my email and the cookie with the format of:

csrftoken=“xyz”;LEETCODE_SESSION=“xyz”;

Hope this will help.

你好,邮件收到了,会尽快回复。

For people facing same issue as the original post: May be useful to somebody to note that after a few attempts the only way I was able to get it working with the cookie login was by using the cookie value specifically in the header for home/. image

@saksham1211 Did you find a solution somehow? I have the same issue with you and none of the above solutions works. BTW, I am on macOS Monterey. Can anyone help, please? Thank you so much

On macOS Monterey using Safari ⬇️

  1. Login Leetcode (US).
  2. Right Click, select inspect element (“Show Dev Menu in menu bar” must be enabled)
  3. Click on Leetcode Logo on website header.
  4. Select “Network” tab, followed by XHR/Fetch.
  5. Select “graphql” on left, under “Header Request” copy entire cookie string.

In VScode 😎

  1. Open new terminal.
  2. Type “leetcode user -c”
  3. Type Username, hit return, then paste the cookie when prompted, hit return.
  4. Quit VScode, re-open application.
Screen Shot 2022-02-20 at 12 39 54 PM

Thanks for your help. However when I type in “leetcode user -c” there is an error and it is not working when try to type my username and cookie, check the screenshot.

Screen Shot 2022-02-21 at 1 03 08 PM

I also tried to use the username and cookie directly(the 4th option in below screenshot), so lucky either.

Screen Shot 2022-02-21 at 1 06 59 PM

Confirmed: cookie login works for US endpoint. The key point is to copy the whole cookie, not just the string after the semicolon.

@liuyanfight I locate your problem, maybe you are using leetcode-cn.

  • If you are using leetcode-cn account to login there is no need to cookie login, just use your cn account to login is fine.
  • If you are using leetcode.com account to login you have to change your endpoint from leetcode.cn to leetcode first.
  • then follow the steps to cookie login

And I think I can change leetcode-cn in up-stream repo in the future to make the log more clear

# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

@wuyifat Update vscode-leetcode and reload then “ctrl + shift + p” type sign in by cookie could work for now.

It did works now, great catch and response.


# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

@wuyifat Update vscode-leetcode and reload then “ctrl + shift + p” type sign in by cookie could work for now.

Hi @ericjjj,

Would you mind to explain more about your solution?

Thanks.

Is there a way to paste the cookies from browser into the extension? So it doesn’t have to automate the login process. @jdneo

你好,邮件收到了,会尽快回复。

it’s still not working , i tried it with my email and the cookie with the format of: csrftoken=“xyz”;LEETCODE_SESSION=“xyz”;

user.paid = _user.isCurrentUserPremium; 
                         
TypeError: Cannot read properties of null (reading 'isCurrentUserPremium')

if anyone encounter this issue, you can try to login use cookie

  1. first select the last option [login via cookie]
  2. login in your leetcode account in any browser
  3. open the developer tool of your browser, select [network] tab
  4. click on any request that has header, copy the cookie in the header Screen Shot 2022-05-10 at 11 48 42
  5. back to vscode, input your username,press [enter], then paste the cookie from step 4, then submit

and you will login in your account successfully. 😃

Thank you so much. It is working perfectly. 😃

Thanks, this work for me.

@jdneo @lostindark

  1. I had tried to use puppeteer but using puppeteer will cause a rotbot check problem.
  2. And the sencond way I also do my best to try but faild, and I happend to find that leetcode is beta their app, maybe we can try to get some luck

@jdneo

  1. I have try to session login that user can copy the cookie from chrome(or others) then paste to the vscode input field, one time login then all the others features are not affected so the user can use vscode-leetcode as usual, can I compelete it and pull request for short-term solution ?

The demo will be like below (user can only copy the cookie and vscode-cli will parser it ): image

image

This cookie but need to add some guide。 image

Hi @yihong0618, I was trying to follow this solution to login by using LEETCODE_SESSION value from browser, but it failed with following error message:

image

Could you provide any help?

sorry,bro i still not solve this problem!!! But now i do leetcode in website!

Its ok bro it still works on my end. +1 Screen Shot 2022-02-22 at 4 17 48 PM

can you please reply in details?

just copying the whole cookie thing would work, not the text “csrftoken***********Z0”. or you could try both. one of them worked for me though

using leetcode.com not leetcode-cn.com cant solve this problem ! image

Found that it might be browser dependent. Copying a cookie from a Chrome network tab works, copying from a Firefox console doesn’t.

Thats true. The cookie format has been changed and there’s no “_sat=1” string towards the end of the cookie anymore.

Gives the same error as above:

    return cb('invalid cookie?');
           ^
TypeError: cb is not a function

@yihong0618 Thank you, as always 👍

@yihong0618 Thanks, it works now.

@yihong0618 Interesting I have not seen such a entry box. I have just tried again, and it shows a popup in the right bottom corner saying that it failed and check the console.

Maybe it is because I have a hardware security key as a 2fa method?

I think so.

@DukeXar when you use your 2FA account, did you wait a few seconds, and there will be a pop up like below image

it should be mentioned,the cookie is captured in the request header when you clicks a button to send a request to leetcode.com.

@LifeOfJona

  1. Please check your vscode-leetcode is the latest version and reload it
  2. Type" Command + Shift + p or F1" then vscode will pop up an input
  3. Then type “Sign In by Cookie” you may see somthing like below image
  4. Enter and maybe wait a little seconds (vscode-leetcode will load data) then type your account image
  5. Paste your cookie from chrome or other
  6. Type Enter and wait for below image

After I input my account and password, it shows “login: login: cookie: [ERROR] invalid cookie?” . still failed.

Any step-by-step instructions to solve the problem temporily ? thanks!

Spent an hour and figured it out. Here are the step by step instructions by people newbie like me.

  1. Make sure Node.js 8+ is installed. Instructions can be found on the official page
  2. Install leetcode-cli from OS terminal or the terminal within vscode. Installation guide. Note the “From Github” section links to an older version.
# to remove the old version
npm uninstall -g leetcode-cli
# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

Type leetcode version in terminal to make sure you installed version 2.6.17+.

  1. Log into leetcode.com in a browser. In Chrome, right click and select “Inspect”. Switch to tab “Network”, “XHR”. Then click any button on leetcode.com(now should be on the left split screen). Now you should be able to see the cookie as @yihong0618 showed in the pic. Copy the entire cookie string starting from “__cfduid” and ending with “_gat=1”
  2. Type leetcode user -c from terminal within vscode. Follow the prompt and type in your username and cookie you copied above.

Hmm, even though I was successfully able to sign in via cookie login none of the problems are being displayed and when I try to sign in again it says “invalid password”. What exactly am I suppose to do when I’m logged in using the cookie method?

And also, Command Shift P isn’t working for me.

It works for me on MacOS . Thanks!!!

@lostindark Thank you for your idea. I have already found some way use OAuth2 for leetcode that leetcode can use third party login to avoid the Recaptcha to login. @jdneo I have a pr in leetcode-tools/leetcode-cli. Not only support third party–github login but also can avoid the Recaptcha and no need to copy the cookie in the browser.

why I am getting ‘Error: You are not login yet?’ when I tried to cookie login with ‘leetcode user -c’?

did the new command has been added to npm already?

OH, just saw the change is only in vscode-leetcode, but I didn’t find that where we could run command in vscode-leetcode, do we have a leetcode-cli in vscode?

@jzbuaa I think maybe over a month. As we login vscode-leetcode before, we never need to re-login (the way to save leetcode-session never changed).

This problem is a little bit tricky. Recaptcha is hard to deal without a browser. I can think of 2 ways to fix this:

  1. Host the login page in an embedded browser, and extract session token when login finishes. puppeteer?
  2. If leetcode supports OAuth2 (I don’t know as I can’t find any document of leetcode API), the plugin can host a client app and use browser to login. Once login finishes and the plugin can get the token for leetcode API.

None of these are simple, maybe we should talk to leetcode and see if there are any support way of login for plugins?