Setting session length with Devise

前端 未结 3 706
我寻月下人不归
我寻月下人不归 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 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
    

提交回复
热议问题