How to provide only authentication of some functions of the elixir module

I am trying to implement Guardian jwt in a phoenixframework project.

I have a user_controller.ex module with the following functions: index, create, show, update and delete

I want users to be authenticated when updating and deleting

If I put plug Guardian.Plug.EnsureAuthenticated, handler: SessionControllerat the beginning of the module, all functions require authentication.

I tried to do this:

plug Guardian.Plug.EnsureAuthenticated, %{ on_failure: { SessionController, :unauthenticated } } when not action in [:index, :create, :show], which works as desired, but I get the following error in the console: [warn] :on_failure is deprecated. Use the :handler option instead

So the question is: how to require authentication when updating and deleting with a handler argument?

+4
source share
1 answer

plug Guardian.Plug.EnsureAuthenticated, [handler: SessionController] when action in [:update, :delete]

+7
source

All Articles