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

Package does not work because login fails

Open apuchitnis opened this issue 4 years ago • 3 comments

I tried to test this package, but it doesn't work for me.

I followed these instructions:

  • Move .env.example to .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.

apuchitnis avatar Jul 19 '21 09:07 apuchitnis

same issu here

kljopu avatar Aug 31 '21 03:08 kljopu

This is because Leetcode is using reCAPTCHA nowadays, so the login method used in the code is not enough.

CleanShot 2021-10-02 at 12 33 33@2x

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;

CleanShot 2021-10-02 at 12 23 28@2x

Nunatic02 avatar Oct 02 '21 19:10 Nunatic02

Thanks a lot, using Leetcode_session works for me.

rohitkrishna094 avatar Oct 03 '21 22:10 rohitkrishna094