Sha256: 162f25a79318cb075f41ee1524eae37a1eb7d697ae30b86689a9f8d76a24b8a6

Contents?: true

Size: 1.33 KB

Versions: 9

Compression:

Stored size: 1.33 KB

Contents

// Create a timer that will poll to see if the user's session is still valid.
// If it isn't, the server returns a 401 unauthorised causing a redirect the login page.
// Note that we could in the future display a message letting them know their session
// will expired in X seconds. The controller action we hit here could be expanded to
// to render some js that would insert than into the page.
// Note we don't want to poll if we are sat on the login page anyway. For one thing on Heroku it
// would prevent a dyno sleeping, but its also a waste of resources.
//
$(document).ready(function() {

  var login_path ="<%= Renalware::Engine.routes.url_helpers.new_user_session_path %>";
  var defaultPollFreq = <%= Renalware.config.session_timeout_polling_frequency.to_i %>;
  var frequency_s = defaultPollFreq;

  // This is a global window function so that we can call it directly from capybara tests to
  // bypass having to wait for the session polling interval to tick over.
  window.sessionTimeoutCheck = function(){
    if(window.location.pathname != login_path) {
      $.getScript("<%= Renalware::Engine.routes.url_helpers.session_timed_out_path %>")
       .fail(function(jqxhr, settings, exception) {
         console.log("Failed to query for session timeout");
       });
    }
  };

  setInterval(window.sessionTimeoutCheck, (frequency_s * 1000));
});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc3 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.rc1 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.beta12 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.beta11 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.beta10 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.beta9 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.beta8 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.beta7 app/assets/javascripts/renalware/session_timeout_redirect.js.erb
renalware-core-2.0.0.pre.beta6 app/assets/javascripts/renalware/session_timeout_redirect.js.erb