1
votes

We are using Devise, Rails_Admin and Simple_Token_Authentication (for API) in our application.

Everything is working fine except for sign out. When we click on Sign out, following request is made and the user gets signed out.

Started DELETE "/admins/sign_out" for 127.0.0.1 at 2015-07-12 18:50:44 +0530 Processing by Devise::SessionsController#destroy as HTML Parameters: {"authenticity_token"=>"rtSRPzpRN7cWEk8wV8q6VDAUB575ZV46JeFFlMFVOQc="} Admin Load (0.4ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = 1 ORDER BY "admins"."id" ASC LIMIT 1 (0.1ms) begin transaction (0.1ms) commit transaction Completed 204 No Content in 700ms (ActiveRecord: 0.5ms)

The problem is that the page does not redirect after sign out.

On pressing the sign out button again, here is the request:

Started DELETE "/admins/sign_out" for 127.0.0.1 at 2015-07-12 19:01:59 +0530 Processing by Devise::SessionsController#destroy as HTML Parameters: {"authenticity_token"=>"dHuxA5hRosyquhlsRmchK3vW9bQOCM/YXYXUNMxTufc="} Filter chain halted as :verify_signed_out_user rendered or redirected Completed 204 No Content in 1ms (ActiveRecord: 0.0ms)

Here is the application controller (app/controllers/application_controller.rb):

class ApplicationController < ActionController::Base

  protect_from_forgery

  skip_before_filter :verify_signed_out_user

  respond_to :html, :json

  protected

  # Overwriting the sign_out redirect path method   
  def after_sign_out_path_for(resource_or_scope)        
   request.referrer   
  end 
end

Here is the devise related code in app/config/initializers/rails_admin.rb

config.authenticate_with do   
  warden.authenticate! scope: :admin   
end
config.current_user_method(&:current_admin)

Please suggest. Thanks in advance!

1
Don't know if this will work or not but can you try making a custom SessionsController < Devise::SessionsController inheriting devise controller and adding this in routes file and adding skip_before_filter :verify_signed_out_user, only: :destroy there.Deepesh
Hi Deep. Already tried that.. didn't work.Nirav Shah
There is one more method written to be overided in this link Devise::Controllers::Helpers#stored_location_for github.com/plataformatec/devise/wiki/… may be this help youDeepesh
Try changing request.referrer in after_sign_out_path to root_path.Pavan
Hi Pavan, it does not workNirav Shah

1 Answers

1
votes

The problem is in your after_sign_out_path_for(resource_or_scope).

request.referrer redirects to the current page.

Change the after_sign_out_path_for(resource_or_scope) accordingly. If you want to redirect to root_path, then below would work.

def after_sign_out_path_for(resource_or_scope)        
   root_path   
end