I have set up guardian to encode specific permissions in the token, however, I would like to restrict this in my UserController
to just require it on specific actions ([:index, :show, :edit, :update, :delete]
). I use the following line at the top of the controller to require the admin: [:cms]
permission for the entire controller:
plug Guardian.Plug.EnsurePermissions, handler: Ay.Guardian.ErrorHandler, admin: [:cms]
This works fine but I would like to add a guard like clause to this (e.g. when action in [:index, :show, :edit, :update, :delete]
) but I can't seem to get this to work the way I want to.
I realize I can easily check the claims in each action but because of the large amount of controllers I would like a more generic approach.
Try calling the plug like this:
(the
[]
are important!)To make it a bit more readable try
alias
the plug like: