Skip to content
Discussion options

You must be logged in to vote

Found the answer. We can add a signin callback:

  callbacks: {
    signIn: async (user, account, metadata) => {
      if (account.provider !== 'github') return;

      const emailRes = await fetch('https://api.github.com/user/emails', {
        headers: {
          Authorization: `token ${account.accessToken}`,
        },
      });
      const emails = await emailRes.json();
      const primaryEmail = emails.find(e => e.primary).email;

      user.email = primaryEmail;
    },
  },

We could add this to the documentation under the Github provider since many users do need the user email.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@TimNZ
Comment options

Answer selected by junaid33
Comment options

You must be logged in to vote
1 reply
@balazsorban44
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
4 participants