简体   繁体   中英

Bypass custom authentication method for active admin rails

I have my application_controller.rb as

attr_reader :current_user
private
def authenticate_request
    headers = request.headers
    uid = headers['uid']
    response = User.find_by(:UID => uid)
    @current_user ||= response
    render(json: { message: 'failed', error: "User Could'nt able to authenticate" }, status: :unprocessable_entity) && return unless response
end

When I start the rails server and try to open http://localhost:3000/admin/ I get error code as

{"message":"failed","error":"User Could'nt able to authenticate"}

How to bypass this custom authenticate_request method for active admin. I can't find any controller related to active admin in the controller's folder.

I am assuming that you have Admin Controller extending application controller, if so then, On your Admin controller on top, do:

skip_before_action :authenticate_request, only: [:index]

Here i am assuming you want to skip validation for index method, if you want same for other the just add those method like:

skip_before_action :authenticate_request, only: [:index, :show, :destroy]

if you would rather skip validation for all method in controller then do only:

 skip_before_action :authenticate_request

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