Closed mplewis closed 11 months ago
Hi @mplewis! Thank you for using passwordless!
First off, I see nothing explicitly wrong with your approach, so if it works it works 😊
If you don't want to patch the existing controller, you could do something like
RailsAdmin.config do |config|
config.authorize_with do |controller|
class PasswordlessAdminHelper
extend Passwordless::ControllerHelpers
end
user = PasswordlessAdminHelper.authenticate_by_session(User)
redirect_to main_app.root_path unless user&.superuser
end
end
I think that could work. You also create your very own, "real" controller and set that as RA's parent controller:
RailsAdmin.config do |config|
config.parent_controller = '::AdminParentController'
config.authenticate_with do
require_admin!
end
end
# app/controllers/admin_parent_controller.rb
class AdminParentController < ActionController::Base
private
def require_admin!
current_user.superuser || redirect_to root_path
end
end
Thanks for the suggestions! I took a look and found that the original one – editing RailsAdmin::MainController
– seems to work with the least caveats.
Do you want me to add something in the Passwordless docs that includes this example as a way to integrate with Pundit?
Great!
Yes, a note would be great. I'm considering whether the project Wiki would be a better place to put it than the Readme? What do you think?
I can't seem to access the wiki for this project. I generally feel like the readme is more accessible because you can Cmd-F for everything you need in one spot. I'm happy to put this info wherever you like – let me know!
Let's just do the Readme 👍 Thanks!
Hi @mikker, thanks so much for building Passwordless! It does exactly what I need.
I am using this with rails_admin via the manual custom auth approach.
My user class looks like this:
I've sort of hacked something together that enables access if a user is signed in and has
superuser: true
. It looks like this:However, this doesn't seem ideal. I don't like hacking the main admin controller open every request, but I can't seem to get at the
authenticate_by_session
method any other way.Do you have any suggestions for what I could try? Happy to PR something to add support for Passwordless into that repo if I can get it working in an ergonomic way.