Skip to content

Commit

Permalink
Merge pull request #238 from pow-auth/log-user-create-failed
Browse files Browse the repository at this point in the history
Log error when user can't be created
  • Loading branch information
danschultzer authored Mar 28, 2023
2 parents b2a06b7 + e0c6da1 commit c637e6b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.4.17 (TBA)

### Enhancements

* [`PowAssent.Phoenix.AuthorizationController`] Now logs error for when user can't be created

## v0.4.16 (2023-03-21)

Now uses Phoenix 1.7 components templating and requires Pow 1.0.29.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ defmodule PowAssent.Phoenix.AuthorizationController do
|> redirect(to: routes(conn).path_for(conn, RegistrationController, :add_user_id, [provider]))
end)
end
def respond_callback({:error, conn}) do
def respond_callback({:error, %{private: %{pow_assent_callback_state: {:error, :create_user}, pow_assent_registration: false}} = conn}) do
conn
|> put_flash(:error, extension_messages(conn).could_not_sign_in(conn))
|> redirect(to: routes(conn).session_path(conn, :new))
end
def respond_callback({:error, %{private: %{pow_assent_callback_state: {:error, :create_user}, pow_assent_callback_error: changeset}} = conn}) do
Logger.error("Unexpected error inserting user: #{inspect changeset}")

conn
|> put_flash(:error, extension_messages(conn).could_not_sign_in(conn))
|> redirect(to: routes(conn).session_path(conn, :new))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ defmodule PowAssent.Phoenix.AuthorizationControllerTest do
test "when identity doesn't exist and missing params", %{conn: conn} do
set_oauth2_test_endpoints(user: %{sub: "new_user", name: ""})

conn = get conn, Routes.pow_assent_authorization_path(conn, :callback, @provider, @callback_params)
assert capture_log(fn ->
conn = get conn, Routes.pow_assent_authorization_path(conn, :callback, @provider, @callback_params)

assert redirected_to(conn) == Routes.pow_session_path(conn, :new)
assert get_flash(conn, :error) == "Something went wrong, and you couldn't be signed in. Please try again."
refute conn.resp_cookies["pow_assent_auth_session"]
refute get_pow_assent_session(conn, :session_params)
assert redirected_to(conn) == Routes.pow_session_path(conn, :new)
assert get_flash(conn, :error) == "Something went wrong, and you couldn't be signed in. Please try again."
refute conn.resp_cookies["pow_assent_auth_session"]
refute get_pow_assent_session(conn, :session_params)
end) =~ "Unexpected error inserting user: #Ecto.Changeset<action: :insert"
end

test "when identity doesn't exist and missing user id", %{conn: conn} do
Expand Down

0 comments on commit c637e6b

Please sign in to comment.