Applying Pundit policies to rodauth features #430
rennel-tenten
started this conversation in
General
Replies: 2 comments 2 replies
-
I'm not sure, as I've never used Pundit. If before_create_account_route do
unless authorize(:account_management, :create?)
# return a response
# set_response_error_status(status)
# return_response("response body")
# set flash error and redirect
# set_redirect_error_flash "Not admin"
# redirect '/some/path'
end
end Note that this uses |
Beta Was this translation helpful? Give feedback.
0 replies
-
The class RodauthMain < Rodauth::Auth
include Pundit::Authorization # this is what gets included into Rails controllers
configure do
before_create_account do
authorize(:account_management, :create?)
end
end
private
def authorize(...)
super
rescue Pundit::NotAuthorizedError
set_redirect_error_flash "Not authorized for this action"
redirect default_redirect
end
def pundit_user
account! # or `rails_account` if you're using rodauth-rails
end
end |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to regulate access to some rodauth endpoints using Pundit policies. For example, I would like to make it so that only accounts that have the role "admin" can create new accounts. Is this possible? If so, how would I go about doing this?
The code below does not work but it illustrates what I want to do:
Beta Was this translation helpful? Give feedback.
All reactions