Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting session length with Devise

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 setting for this.

like image 326
joshs Avatar asked Feb 01 '11 19:02

joshs


3 Answers

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.

like image 176
Brian Deterling Avatar answered Oct 02 '22 12:10

Brian Deterling


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
like image 32
Ankush Avatar answered Oct 02 '22 12:10

Ankush


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
like image 32
rusllonrails Avatar answered Oct 02 '22 12:10

rusllonrails