Active Admin authentication conflicting with User authentication

后端 未结 4 1321
你的背包
你的背包 2021-01-02 03:07

Active Admin is a gem used for having an admin dashboard in your application. It uses Devise for logging in users and creates a separate admin_user model for th

相关标签:
4条回答
  • 2021-01-02 03:28

    I was able to solve this. The issue was related to Devise expecting a single user model in the application. Here is how to fix it.

    In the config/initializers/devise.rb file, add:

    config.scoped_views = true
    

    and

    config.default_scope = :user #or whichever is your regular default user model
    

    thats it, warden checks the :user for being logged in and not :admin_user

    0 讨论(0)
  • 2021-01-02 03:35

    What worked for me is:

    constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.instance_of?(AdminUser) }
    
    0 讨论(0)
  • 2021-01-02 03:47

    I am not sure, but you can try something like

    root :to => proc { |env| [ 302, {'Location'=> env["warden"].authenticate? ? "users/dashboard" : "/home" }, [] ] }
    
    0 讨论(0)
  • 2021-01-02 03:51

    Why are you using the get "/"? You should remove it. I'm using a definition pretty similar to yours and works fine with me. Use just:

    root :to => 'users#dashboard', :constraints => lambda {|r| r.env["warden"].authenticate? }
    root :to => 'home#index'
    
    0 讨论(0)
提交回复
热议问题