如何仅确保对 elixir 模块中的某些功能进行身份验证
How to only ensure authenticated on some functions in elixir module
我正在尝试在 phoenixframework 项目中实施 Guardian jwt。
我有一个 user_controller.ex 模块,具有以下功能:索引、创建、显示、更新和删除
我只想确保用户在更新和删除时经过身份验证
如果我把 plug Guardian.Plug.EnsureAuthenticated, handler: SessionController
放在模块的顶部 所有 函数都需要身份验证。
我试过这样做:
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 action in [:update, :delete]
我正在尝试在 phoenixframework 项目中实施 Guardian jwt。
我有一个 user_controller.ex 模块,具有以下功能:索引、创建、显示、更新和删除
我只想确保用户在更新和删除时经过身份验证
如果我把 plug Guardian.Plug.EnsureAuthenticated, handler: SessionController
放在模块的顶部 所有 函数都需要身份验证。
我试过这样做:
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 action in [:update, :delete]