vscode-leetcode icon indicating copy to clipboard operation
vscode-leetcode copied to clipboard

TypeError: cb is not a function

Open xiaoheiAh opened this issue 4 years ago • 12 comments

🐛 Bug Report

login by username and cookie

To Reproduce

Steps to reproduce the behavior.

Expected behavior

A clear and concise description of what you expected to happen.

Extension Output

login: cookie: /Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:555
    return cb('invalid cookie?');
           ^

TypeError: cb is not a function
    at parseCookie (/Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:555:12)
    at Plugin.plugin.cookieLogin (/Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js:578:22)
    at /Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/vsc-leetcode-cli/lib/commands/user.js:119:12
    at /Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/prompt/lib/prompt.js:336:32
    at /Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/utile/node_modules/async/lib/async.js:154:25
    at assembler (/Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/prompt/lib/prompt.js:333:9)
    at /Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/prompt/lib/prompt.js:342:32
    at /Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/prompt/lib/prompt.js:625:5
    at Interface.onLine (/Users/otis.z/.vscode/extensions/shengchen.vscode-leetcode-0.16.1/node_modules/read/lib/read.js:111:5)
    at Interface.emit (events.js:198:13)

Guidance: Press Ctrl+Shift+U, and toggle the channel to LeetCode.

Your Environment

  • os: MacOS 10.15
  • extension settings:
    • "leetcode.nodePath": "/usr/local/bin/node"
    • "leetcode.endpoint": "leetcode-cn"
    • "leetcode.defaultLanguage": "java"
  • nodejs version: v10.16.0
  • vscode version: 1.42
  • extension version: 0.16.1

xiaoheiAh avatar Feb 25 '20 11:02 xiaoheiAh

for anyone having this problem, until it fixed, here is a workaround...

Terminal:

# Get leetcode CLI tools
npm install -g skygragon/leetcode-cli

# Create and open user.json file
cd ~/.lc/leetcode/user.json && code user.json

user.json:

// Enter login credentials to user.json
// From browser, login to leetcode, then Dev tools -> Application -> Cookies
// You would need LEETCODE_SESSION and csrftoken
{
    "login": "",       //username
    "sessionCSRF": "", //paste "csrftoken"
    "sessionId": "",   //paste "LEETCODE_SESSION"
}

Restart vscode, and you should be logged in.

BatuhanKorur avatar Feb 29 '20 04:02 BatuhanKorur

for anyone having this problem, until it fixed, here is a workaround...

Terminal:

# Get leetcode CLI tools
npm install -g skygragon/leetcode-cli

# Create and open user.json file
cd ~/.lc/leetcode/user.json && code user.json

user.json:

// Enter login credentials to user.json
// From browser, login to leetcode, then Dev tools -> Application -> Cookies
// You would need LEETCODE_SESSION and csrftoken
{
    "login": "",       //username
    "sessionCSRF": "", //paste "csrftoken"
    "sessionId": "",   //paste "LEETCODE_SESSION"
}

Restart vscode, and you should be logged in.

I tried but it didn't work for me

xiaoheiAh avatar Mar 02 '20 11:03 xiaoheiAh

for anyone having this problem, until it fixed, here is a workaround...

Terminal:

# Get leetcode CLI tools
npm install -g skygragon/leetcode-cli

# Create and open user.json file
cd ~/.lc/leetcode/user.json && code user.json

user.json:

// Enter login credentials to user.json
// From browser, login to leetcode, then Dev tools -> Application -> Cookies
// You would need LEETCODE_SESSION and csrftoken
{
    "login": "",       //username
    "sessionCSRF": "", //paste "csrftoken"
    "sessionId": "",   //paste "LEETCODE_SESSION"
}

Restart vscode, and you should be logged in.

Work for me, thanks!

ccat3z avatar Mar 09 '20 08:03 ccat3z

for anyone having this problem, until it fixed, here is a workaround...

Terminal:

# Get leetcode CLI tools
npm install -g skygragon/leetcode-cli

# Create and open user.json file
cd ~/.lc/leetcode/user.json && code user.json

user.json:

// Enter login credentials to user.json
// From browser, login to leetcode, then Dev tools -> Application -> Cookies
// You would need LEETCODE_SESSION and csrftoken
{
    "login": "",       //username
    "sessionCSRF": "", //paste "csrftoken"
    "sessionId": "",   //paste "LEETCODE_SESSION"
}

Restart vscode, and you should be logged in.

Thanks! It work.

Uddoo avatar Apr 01 '20 01:04 Uddoo

thanks

amintong avatar Sep 03 '20 18:09 amintong

@BatuhanKorur Thanks a lot!

chiraggandhi123 avatar Sep 11 '20 13:09 chiraggandhi123

for anyone having this problem, until it fixed, here is a workaround...

Terminal:

# Get leetcode CLI tools
npm install -g skygragon/leetcode-cli

# Create and open user.json file
cd ~/.lc/leetcode/user.json && code user.json

user.json:

// Enter login credentials to user.json
// From browser, login to leetcode, then Dev tools -> Application -> Cookies
// You would need LEETCODE_SESSION and csrftoken
{
    "login": "",       //username
    "sessionCSRF": "", //paste "csrftoken"
    "sessionId": "",   //paste "LEETCODE_SESSION"
}

Restart vscode, and you should be logged in.

c:\Users\lxcx.vscode\extensions\leetcode.vscode-leetcode-0.17.0\node_modules\vsc-leetcode-cli\lib\commands\user.js:146 "login": "[email protected]", //username ^

SyntaxError: Unexpected token ':' at wrapSafe (internal/modules/cjs/loader.js:1053:16) at Module._compile (internal/modules/cjs/loader.js:1101:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Module.load (internal/modules/cjs/loader.js:985:32) at Function.Module._load (internal/modules/cjs/loader.js:878:14) at Module.require (internal/modules/cjs/loader.js:1025:19) at Object.require (internal/modules/cjs/helpers.js:72:18) at c:\Users\lxcx.vscode\extensions\leetcode.vscode-leetcode-0.17.0\node_modules\require-directory\index.js:76:17 at Array.forEach () at requireDirectory (c:\Users\lxcx.vscode\extensions\leetcode.vscode-leetcode-0.17.0\node_modules\require-directory\index.js:59:24)


I can't understand this question...:(

HuSharp avatar Nov 14 '20 14:11 HuSharp

image

code ~/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js 

sessionId is cookie.LEETCODE_SESSION in devtools application panel. sessionCSRF is cookie.csrftoken in devtools application panel.

find line 541, follow above step. Restart, login success!

EliazTray avatar Aug 23 '22 03:08 EliazTray

image

code ~/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js 

sessionId is cookie.LEETCODE_SESSION in devtools application panel. sessionCSRF is cookie.csrftoken in devtools application panel.

find line 541, follow above step. Restart, login success!

it works, obviously. but it feels too weird to have to resort to such measures...

shinya17 avatar May 29 '23 00:05 shinya17

image

code ~/.vscode/extensions/leetcode.vscode-leetcode-0.18.1/node_modules/vsc-leetcode-cli/lib/plugins/leetcode.js 

sessionId is cookie.LEETCODE_SESSION in devtools application panel. sessionCSRF is cookie.csrftoken in devtools application panel.

find line 541, follow above step. Restart, login success!

It works, Thank you!

polar9527 avatar Aug 23 '23 01:08 polar9527

The actual reason is that leetcode is not sending LEETCODE_SESSION and sessionCSRF in all the HTTP requests. It is only included in the graphql requests.

Using the cookie from https://leetcode.com/graphql/ request would work without changing anything in the plugin.

LucasD11 avatar Sep 28 '23 18:09 LucasD11

The actual reason is that leetcode is not sending LEETCODE_SESSION and sessionCSRF in all the HTTP requests. It is only included in the graphql requests.

Using the cookie from https://leetcode.com/graphql/ request would work without changing anything in the plugin.

Using the cookie from https://leetcode.com or https://leetcode.com/graphql. Both cookies work for me.

xxxVitoxxx avatar Jan 15 '24 03:01 xxxVitoxxx