devise icon indicating copy to clipboard operation
devise copied to clipboard

after_sign_in_path_for does not work

Open muhammedtufekyapan opened this issue 5 years ago • 2 comments

Hi everyone,

  • Ruby v 2.6.3p32
  • Rails v 6.0.2.1
  • Devise v 4.7.1

I use three different Devise model with two domains. My routes.rb looks like this;

Rails.application.routes.draw do
  constraints host: 'domain1.com' do
    ActiveAdmin.routes(self)
    devise_for :users, ActiveAdmin::Devise.config.merge(path: 'user')
    devise_for :admin_users, ActiveAdmin::Devise.config.merge(path: 'admin')
    root to: "users/dashboard#index", :as => :user
  end

  constraints host: 'domain2.com' do
    resources :lists
    devise_for :influencers
    get '/lists' => 'lists#index', as: :influencer_root
    root to: "lists#index", as: "All_List_Objects"
  end

end

Also I added

def after_sign_in_path_for (resource)
    stored_location_for(resource) ||
    if resource.is_a?(Influencer)
      return "/"
      # return "/lists"
    elsif resource.class == User
      return "/"
    else
      root_path
    end
  end

to my Aplication_Controller.rb

Current behavior

I got these logs;

Redirected to http://localhost:3000/lists
Completed 302 Found in 126ms (ActiveRecord: 4.6ms | Allocations: 13282)

Expected behavior

I want to redirect to "/" after Influencers signed up with 200 code.

How can I solve it?

muhammedtufekyapan avatar Jul 19 '20 15:07 muhammedtufekyapan

From looking at it, I'm imagining that there might be a stored location that it could be using. If that's not the case, can you please provide a sample app that shows the issue? If possible, without active admin involved.

carlosantoniodasilva avatar Jul 24 '20 16:07 carlosantoniodasilva

From looking at it, I'm imagining that there might be a stored location that it could be using. If that's not the case, can you please provide a sample app that shows the issue? If possible, without active admin involved.

what is the recommended ways to override default devise method?

did putting the overrided code on application_controller.rb okay? or there is preferable way than that?

class ApplicationController < ActionController::Base
  before_action :authenticate_user!

  def after_sign_in_path_for(resource_or_scope)
    signed_in_root_path(resource_or_scope)
  end
end

laptopmutia avatar Feb 27 '24 12:02 laptopmutia