Skip to content
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

Unable to get User Information #93

Open
AnuragAnalog opened this issue Aug 23, 2024 · 4 comments
Open

Unable to get User Information #93

AnuragAnalog opened this issue Aug 23, 2024 · 4 comments

Comments

@AnuragAnalog
Copy link

Unable to get user information

Code used to reproduce

import { LeetCode } from "leetcode-query";

const leetcode = new LeetCode();
const user = await leetcode.user("username");

Error

Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
    at _fetch (index.js:71:1)
    at get_csrf (index.js:87:1)
    at Credential.init (index.js:111:1)
    at getUser (Card.js:10:1)
    at Card (Card.js:15:1)
    at renderWithHooks (react-dom.development.js:15486:1)
    at mountIndeterminateComponent (react-dom.development.js:20103:1)
    at beginWork (react-dom.development.js:21626:1)
    at beginWork$1 (react-dom.development.js:27465:1)
    at performUnitOfWork (react-dom.development.js:26596:1)

Help me with this. @JacobLinCool

@JacobLinCool
Copy link
Owner

Hello. Which environment did you run it on? I tested it, and the code works on Node, Deno, and Bun without any problems.

@diragb
Copy link

diragb commented Oct 3, 2024

facing a similar issue, this is on nextjs

@AnuragAnalog
Copy link
Author

Hello. Which environment did you run it on? I tested it, and the code works on Node, Deno, and Bun without any problems.

I tried to run the code in React, and I was facing error, the react boilerplate code was created using create-react-app.

@JacobLinCool
Copy link
Owner

Ok, please check the following:

  1. It may not be possible to use it in the browser due to the CORS problem; please run it in the server environment instead.
  2. If you still encounter this issue on the server side, please try using a custom fetcher:
import { LeetCode, fetcher } from "leetcode-query";

// use a custom fetcher
fetcher.set(fetch);

// use as normal
const lc = new LeetCode();
const daily = await lc.daily();
console.log(daily);

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

3 participants