Package does not work because login fails
apuchitnis opened this issue · 3 comments
apuchitnis commented
I tried to test this package, but it doesn't work for me.
I followed these instructions:
- Move
.env.exampleto.env - Enter my login details
- Run
yarn test. This fails, with the following output:
$ yarn test
...
# Leetcode
Correct Account
1) "before all" hook for "Should be intance of Leetcode"
Incorrect Account
√ Should throw login error (460ms)
# Problem
2) "before all" hook for "Should be instance of Problem"
# Submission
3) "before all" hook for "Should be instance of Submission"
1 passing (2s)
3 failing
1) # Leetcode
Correct Account
"before all" hook for "Should be intance of Leetcode":
Error: Login Fail
at Function.<anonymous> (src\lib\leetcode.ts:68:23)
at step (src\lib\leetcode.ts:32:23)
at Object.throw (src\lib\leetcode.ts:13:53)
at rejected (src\lib\leetcode.ts:5:65)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
2) # Problem
"before all" hook for "Should be instance of Problem":
Error: Login Fail
at Function.<anonymous> (src\lib\leetcode.ts:68:23)
at step (src\lib\leetcode.ts:32:23)
at Object.throw (src\lib\leetcode.ts:13:53)
at rejected (src\lib\leetcode.ts:5:65)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
3) # Submission
"before all" hook for "Should be instance of Submission":
Error: Login Fail
at Function.<anonymous> (src\lib\leetcode.ts:68:23)
at step (src\lib\leetcode.ts:32:23)
at Object.throw (src\lib\leetcode.ts:13:53)
at rejected (src\lib\leetcode.ts:5:65)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
error Command failed with exit code 3.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The output above mentions that the login fails.
kljopu commented
same issu here
Nunatic02 commented
This is because Leetcode is using reCAPTCHA nowadays, so the login method used in the code is not enough.
A quick workaround over this is to find LEETCODE_SESSION and csrfToken values using the chrome network tab when you are logging in manually, like what's shown in the image. Then replace the login function with the code below.
A drawback is that the session will expire after 14 days. So you need to update that manually.
const credit = {
session: LEETCODE_SESSION,
csrfToken: csrfToken,
};
return credit;
rohitkrishna094 commented
Thanks a lot, using Leetcode_session works for me.

