While using passport-github, profile.emails is null despite user:email scope

486 views Asked by At

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?

1

There are 1 answers

0
Dongwook Shin On BEST ANSWER

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.)