ueberauth / guardian

Elixir Authentication
MIT License
3.44k stars 381 forks source link

Phoenix 1.4: Refactor guardian plugs to use put_view/1 #538

Closed egeersoz closed 5 years ago

egeersoz commented 5 years ago

The render/4 function has been deprecated in Phoenix 1.4, so the various guardian plugs need to be updated to use put_view/1 followed by render/3 when rendering.

Warnings are currently reported in the console:

.................warning: Elixir.Phoenix.Controller.render/4 with a view is deprecated, see the documentation for render/3 for an alternative
.  (phoenix) lib/phoenix/controller.ex:719: Phoenix.Controller.render/4
  (guardian) lib/guardian/plug/ensure_authenticated.ex:63: Guardian.Plug.EnsureAuthenticated.respond/1
  (my_app) lib/my_app_web/guardian/auth_pipeline.ex:1: MyAppWeb.AuthPipeline.plug_builder_call/2
  (my_app) lib/my_app_web/router.ex:21: MyAppWeb.Router.api_protected/2
  (my_app) lib/my_app_web/router.ex:1: MyAppWeb.Router.__pipe_through3__/1
  (phoenix) lib/phoenix/router.ex:270: Phoenix.Router.__call__/1
  (my_app) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.plug_builder_call/2
  (my_app) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.call/2
  (phoenix) lib/phoenix/test/conn_test.ex:235: Phoenix.ConnTest.dispatch/5
  test/my_app_web/controllers/catalog_item_controller_test.exs:57: MyAppWeb.ItemControllerTest."some test"/1
  (ex_unit) lib/ex_unit/runner.ex:312: ExUnit.Runner.exec_test/1
  (stdlib) timer.erl:166: :timer.tc/1
  (ex_unit) lib/ex_unit/runner.ex:251: anonymous fn/4 in ExUnit.Runner.spawn_test/3

Example usage of the new put_view/1 function:

conn
|> put_status(:created)
|> put_view(PricetableWeb.AccountView)
|> render("confirm.html", email: user.email)
egeersoz commented 5 years ago

Any news on this?

doomspork commented 5 years ago

@egeersoz a PR is welcomed 👍

Hanspagh commented 5 years ago

I have just had a look at this, guardian doesn't seem to use render anywhere, the warning you are referring to looks like is coming from your own implementation of the error_handler, could that be the case?

egeersoz commented 5 years ago

@Hanspagh Yes, that did indeed turn out to be the case. It wasn't immediately obvious from the stack trace. Thanks for looking into it!