Setting session length with Devise

前端 未结 3 685
我寻月下人不归
我寻月下人不归 2020-12-03 02:42

My sessions with devise timeout after 1-3 hours of non-use (not sure exactly how long). How can I adjust this?

I\'ve looked over the docs and can\'t seem to find a s

相关标签:
3条回答
  • 2020-12-03 02:55

    With Rails4, the better thing to follow is:

    In models/user.rb: Add :timeoutable to already existing list of devise modules.

    class User < ActiveRecord::Base
      devise :timeoutable
    end
    

    In config/initializers/devise.rb: Set the timeout parameter.

    Devise.setup do |config|
      config.timeout_in = 3.hours
    end
    
    0 讨论(0)
  • 2020-12-03 03:11

    Global:

    class User < ActiveRecord::Base
      devise (...), :timeoutable
    end
    
    Devise.setup do |config|
      config.timeout_in = 3.hours
    end
    

    Also it's possible to set timeout_in option dynamically

    class User < ActiveRecord::Base
      devise (...), :timeoutable
    
      def timeout_in
        if self.admin? 
          1.year
        else
          2.days
        end
      end
    end
    
    0 讨论(0)
  • 2020-12-03 03:13

    Look in config/initializers/devise.rb. There are a lot of configuration settings including config.timeout_in. The default in my version is 30 minutes. You can also set it on the model itself:

    class User < ActiveRecord::Base
      devise :timeoutable, :timeout_in => 15.minutes
    

    You can now also set the timeout dynamically.

    0 讨论(0)
提交回复
热议问题