Github Rest API not fetching results on hosting

Viewed 12

I am supposed to use GITHUB REST API to fetch details such as username and repositories of a user. I am getting the results on localhost and when I deploy this project using VERCEL the project is hosted fine. The problem is that in the hosted URL the I am not able to see the results that were supposed to be fetched by the API. This is the error in the console:

GEThttps://api.github.com/users/Xaid-vfx/repos?page=1&per_page=8 [HTTP/2 401 Unauthorized 581ms]
Uncaught (in promise) HttpError: Bad credentials

What I understood is that my Authorisation key is not working whenever I am trying to deploy using vercel. Here's the code that I am using to make API calls

const octokit = new Octokit({
    auth: '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'
  });

useEffect(() => {


    async function get() {

      setloading(true);

      const req1 = await octokit.request('GET /users/{username}/repos?page=1&per_page=1000', {
        username: username
      })

      setsize(req1.data.length)
      console.log(req1.data.size);


      const details = await octokit.request('GET /users/{username}', {
        username: username
      })
      // console.log(details);

      setloading(false)
      return [details.data]
    }


    if (username != '') {
      get().then(function (res) {

        // setrep(res[0]);
        console.log(res[0]);
        setname(res[0].login);
        seturl(res[0].avatar_url);
        setbio(res[0].bio);
        setlink(res[0].html_url)
      })


    }

  }, [count])

This code is working fine on localhost and giving the results . When I deploy using vercel from GitHub, it does not fetch results on localhost as well as the deployed url. This has something to do with authorisation token

0 Answers
Related