简体   繁体   中英

ActiveAdmin Not Working Without Devise

So we just went through the process of removing Devise and rolled out simple bcrypt + cancancan auth system.

Now we are also using ActiveAdmin as our solution for admin part of the web app, which was tied to Devise . Everything is broken on that part of the web app :)

I tried a couple of different things that resolved around adding our own authentication method, but I could not find solution for routes and what else is needed.

We have an AdminUser model that's supposed to be admin users. I did "convert" it to use columns normal users use for passwords ( after we made the switch to bcrypt ), but I am completely lost what to do with ActiveAdmin.

There are several items you may need to reconfigure in config/initializers/active_admin.rb .

You may need to define the authentication method:

# config/initializers/active_admin.rb

# == User Authentication
#
# Active Admin will automatically call an authentication
# method in a before filter of all controller actions to
# ensure that there is a currently logged in admin user.
#
# This setting changes the method which Active Admin calls
# within the application controller.
config.authentication_method = :authenticate_active_admin_user!

# app/controllers/application_controller.rb
def authenticat_active_admin_user!
  # Something that returns true if the current user has access to active admin
end

You may also need to set the current_user method:

# config/initializers/active_admin.rb

# == Current User
#
# Active Admin will associate actions with the current
# user performing them.
#
# This setting changes the method which Active Admin calls
# (within the application controller) to return the currently logged in user.
config.current_user_method = :current_user

# app/controllers/application_controller.rb
def current_user
  # returns the current logged in user.  Devise provides this automatically. You will need to replace that functionality.
end

The above are just two things in the Active Admin initializer that affect logging in and authentication. I would recommend going through the entire and looking at all of the other configs related to user authentication and authorization. The initializer is well documented with comments and there is plenty of documentation in the Active Admin homepage . You may find you need to replace some of the other methods active admin is using for authentication and authorization.

Finally, make sure your CanCanCan Ability class is able to access the current user. If your controller is not passing it the correct user, then it will block access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM