Skip to content

TypeError: cb is not a function #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xiaoheiAh opened this issue Feb 25, 2020 · 12 comments
Open

TypeError: cb is not a function #522

xiaoheiAh opened this issue Feb 25, 2020 · 12 comments

Comments

@xiaoheiAh
Copy link

🐛 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
@BatuhanKorur
Copy link

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.

@xiaoheiAh
Copy link
Author

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

@ccat3z
Copy link

ccat3z commented Mar 9, 2020

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!

@Uddoo
Copy link

Uddoo commented Apr 1, 2020

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.

@amintong
Copy link

amintong commented Sep 3, 2020

thanks

@chiraggandhi123
Copy link

@BatuhanKorur Thanks a lot!

@HuSharp
Copy link

HuSharp commented Nov 14, 2020

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": "husharp@163.com", //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...:(

@EliazTray
Copy link

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!

@shinya17
Copy link

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...

@polar9527
Copy link

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!

@LucasD11
Copy link

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.

@xxxVitoxxx
Copy link

xxxVitoxxx commented Jan 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests