2016-04-02 31 views
4

一些功能驗證我想在phoenixframework項目中實現Guardian jwt。如何才能確保在elixir模塊

我有一個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

所以現在的問題是:如何只需要在更新認證並使用處理程序參數刪除?

+1

是否'堵塞Guardian.Plug.EnsureAuthenticated,[處理程序:SessionController]在不操作[:索引:創建:秀]'工作? – Dogbert

回答

7

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

相關問題