ruby-on-railsdynamicdevisesession-timeoutsession-store

Rails dynamic session timeout using devise and session store


I know i can do dynamic session timeout (per user) with devise like described here

This worked fine before but now i'm using rails session store and it doesn't work anymore.

I googled quite a long time but didn't find an answer, does anyone know how to do this?

Thanks


Solution

  • I've done it now with some before_filters:

    class ApplicationController < ActionController::Base
      before_filter :update_session, :check_if_session_is_valid
    
      ...
      def check_if_session_is_valid
        session_timeout = current_user.try(:session_timeout) || 1800
        if session[:timestamp] <= session_timeout.seconds.ago.to_i
          session[:user_id] = nil
        end
      end
    
      def update_session
        session[:timestamp] = Time.now.to_i
      end
    

    And in the controller which is used by the poller i added this (the session shouldn't get updated by the poller):

    skip_before_filter :update_session, :only => :get_new