Skip to content

Commit

Permalink
Add fallback when email's not in token (#1686)
Browse files Browse the repository at this point in the history
Fixes #1684
  • Loading branch information
jamilbk committed Jun 23, 2023
1 parent ccae7ba commit 47417d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/fz_http/lib/fz_http_web/user_from_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ defmodule FzHttpWeb.UserFromAuth do
end
end

# Fallback
def find_or_create(_provider_id, _params) do
{:error, "unknown provider or email not found in params"}
end

defp maybe_create_user(idp_field, provider_id, email) do
if Auth.auto_create_users?(idp_field, provider_id) do
Users.create_user(:unprivileged, %{email: email})
Expand Down
5 changes: 5 additions & 0 deletions apps/fz_http/test/fz_http_web/user_from_auth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ defmodule FzHttpWeb.UserFromAuthTest do
assert Users.fetch_user_by_email(email) == {:error, :not_found}
end
end

describe "find_or_create/2 with missing email" do
assert {:error, "unknown provider or email not found in params"} =
UserFromAuth.find_or_create("dummy", %{"sub" => "1234"})
end
end

1 comment on commit 47417d3

@vercel
Copy link

@vercel vercel bot commented on 47417d3 Jun 23, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.