Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally fetch email #78

Merged
merged 3 commits into from
May 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/ueberauth/strategy/github.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ defmodule Ueberauth.Strategy.Github do
name: user["name"],
description: user["bio"],
nickname: user["login"],
email: fetch_email!(user, allow_private_emails),
email: maybe_fetch_email(user, allow_private_emails),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we couldn't update fetch_email! to avoid raising an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of two places where fetch_email! used to be used. The other one seems to be a legit place for raising with the expectation of the field existence.

Also, get_primary_email! and get_private_email! do no raise, so I could clean them up to have no ! in the names and call maybe_fetch_email from fetch_email!.

location: user["location"],
image: user["avatar_url"],
urls: %{
Expand Down Expand Up @@ -219,6 +219,12 @@ defmodule Ueberauth.Strategy.Github do
conn.private.github_user[field]
end

defp maybe_fetch_email(user, allow_private_emails) do
user["email"] ||
get_primary_email!(user) ||
get_private_email!(user, allow_private_emails)
end

defp fetch_email!(user, allow_private_emails) do
user["email"] ||
get_primary_email!(user) ||
Expand Down