Skip to content

Commit

Permalink
Check for email.visibility also when looking for user email. (#437)
Browse files Browse the repository at this point in the history
* Check for email.visibility also when looking for user email.

* Update the error message when looking for public primary email.

---------

Co-authored-by: Ushi Hiraga <[email protected]>
  • Loading branch information
UshiHiraga and Ushi Hiraga authored Nov 27, 2024
1 parent f337973 commit 233ce24
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions netlify/edge-functions/github-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ async function getUser(token: string) {
throw new Error("Error getting user's emails")
}

const emails = (await emailResponse.json()) as Array<{ email: string; primary: boolean }>
const primaryEmail = emails.find((email) => email.primary)
const emails = (await emailResponse.json()) as Array<{ email: string; primary: boolean; visibility: string }>
const primaryEmail = emails.find((email) => email.primary && email.visibility === "public")

if (!primaryEmail) {
throw new Error("No primary email found")
throw new Error("No public primary email found. Check your privacy settings in https://github.com/settings/emails")
}

return { login, name, email: primaryEmail.email }
Expand Down

0 comments on commit 233ce24

Please sign in to comment.