views:

199

answers:

1

I'm using Rack to try to implement "Remember Me" functionality in my Sinatra app.

I'm able to set the session cookie to expire when the session ends or in X seconds time but I'd like to do both.

For example, if a user has clicked "remember me" then I wish for their session to end after X seconds. Eg, my app.rb has a line that looks like this:

use Rack::Session::Cookie, :expire_after => 2592000, #30 days in seconds
                           :secret => MY_SECRET

I've tried to do the following when the user logs in:

if (!remember_me)
  env['rack.session.options'][:expire_after] = nil
end

However, this does not set the cookie value.

Does anyone know how to set this?

Thanks in advance.

A: 

This probably has to be done before the session is loaded.

See Rack::Session::Cookie#load_session and Rack::Session::Cookie#commit_session

Rishav Rastogi