'fetching private repositories from GitHub app

I'm building a web app that integrates with GitHub API (authentication). I'm trying to fetch the user's repositories both public and private. But both without accessToken and with accessToken return public repos only.

  1. authentication

  const provider = new GithubAuthProvider();
  provider.addScope('repo');

  const PopupSignIn = async () => {
     const result = await signInWithPopup(auth, provider);
     const credential = GithubAuthProvider.credentialFromResult(result);
     setToken(credential.accessToken)
     return credential;
  };
  1. fetching repositories
    user here is the auth credential got from getAuth()
PopupSignIn().then(() => {
   fetch(
      `https://api.github.com/users/${user.reloadUserInfo.screenName}/repos`,
      { headers: { authorization: token } }
   )
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source