Question

I'm using Clearance for authentication in my Rails app. Does anyone know of a way to configure a session timeout? It's been logging me out within 5 minutes of when I login and I can't seem to locate anything that specifies how to set the timeout.

Était-ce utile?

La solution

When you installed Clearance, I think it should have added a config/initializers/clearance.rb file. You can configure the session timeout in there through the use of the cookie_expiration config. From their docs, it can look like this:

@example
  Clearance.configure do |config|
    config.mailer_sender     = 'me@example.com'
    config.cookie_expiration = lambda { 2.weeks.from_now.utc }
    config.password_strategy = MyPasswordStrategy
    config.user_model        = MyNamespace::MyUser
  end

So, just give cookie expiration a lambda that returns a Time object that occurs sometime in the future.

Autres conseils

Looking at the rdoc, there's a cookie_expiration method on the Clearance configuration class. Here it is -- look at the source for the method:

By default, it looks like it's 1 year:

def initialize
  @mailer_sender     = 'donotreply@example.com'
  @cookie_expiration = lambda { 1.year.from_now.utc }
end

So I'd look at overriding that in the configuration.

http://rdoc.info:8080/github/thoughtbot/clearance/Clearance/Configuration#cookie_expiration-instance_method

If you're unable to find it, sometimes you can ask on the Thoughtbot IRC channel #thoughtbot on freenode. Sometimes the developers hang out there and they'll field questions.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top