1

I'm trying to get the private email of github user via passport-github.
So this is my code with scope: "user:email":

   import passport from "passport";    
    import GithubStrategy from "passport-github";
    
    passport.use(
      new GithubStrategy(
        {
          clientID: process.env.GH_CLIENT_ID,
          clientSecret: process.env.GH_CLIENT_SECRET,
          callbackURL: `http://localhost:4000${routes.ghLoginCallback}`,
          scope: "user:email",
        },
        async (accessToken, refreshToken, profile, cb) => {
          console.log(profile.emails);
        }
      )
    );

And now I get undefined from profile.emails.
I do get my profile correctly, but with email:null also.
Are there any possible problems that I'm missing?

  • Checkout this thread to see if it helps. https://github.com/jaredhanson/passport-github/issues/15 If there are issues you could potentially use `passport-github2` is actively maintained and has an example of how to get email data. – jasonandmonte Oct 07 '20 at 21:12

1 Answers1

0

yeah as @jasonandmonte mentioned, passport-github2 worked for me! Thanks a lot.
However, some people are saying that only passport-github works for them (checkout the thread that @jasonandmonte mentioned), so anyone who are in same issue in future can try both one. (Structure is almost the same.)