-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ideas for compatibility with rails_admin? #95
Comments
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 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.
The text was updated successfully, but these errors were encountered: