【发布时间】:2016-04-03 00:54:17
【问题描述】:
我正在尝试在 phoenixframework 项目中实现 Guardian jwt。
我有一个 user_controller.ex 模块,它具有以下功能:索引、创建、显示、更新和删除
我只想确保用户在更新和删除时通过身份验证
如果我把plug Guardian.Plug.EnsureAuthenticated, handler: SessionController 放在模块的顶部all 函数需要身份验证。
我尝试过这样做:
plug Guardian.Plug.EnsureAuthenticated, %{ on_failure: { SessionController, :unauthenticated } } when not action in [:index, :create, :show],确实按要求工作,但我在控制台中收到以下错误:[warn] :on_failure is deprecated. Use the :handler option instead
所以问题是:如何只要求在更新和删除时使用处理程序参数进行身份验证?
【问题讨论】:
-
plug Guardian.Plug.EnsureAuthenticated, [handler: SessionController] when not action in [:index, :create, :show]工作吗?