View Full Version : Checking for user session.

24 Jun 2010, 5:14 AM
The app requires a user session which is set upon login.
However I'm wondering the best way to implement a checker for the session to ensure it has not expired.

Is there some sort of master event that I can listen to? This is to check for any attempts to make a call to the server i.e. via Ext such as the AJAX call or datastore url loading I can then call the server to check for the user session to make sure they are still active else redirect them to the login page.

I'd rather not have some interval constantly running and hitting the server, unless that is really the better option.

Actually polling is not an option as it would be a request from the client to server thus resetting the counter for the session time out.

24 Jun 2010, 7:45 AM
No master event that I know of. The client doesn't know whether the server has dropped the session, however whenever the server receives requests from the client, the server's session timeout zeros out and recounts as you mentioned.

You could build into your server a central controller, that checks if the session timed out, and redirects the user to a login or there are alternate ways of maintaining session if the user request it (most sites allow "remember me", possibly an unexpired cookie session). There must be some resources out there to point the way.

24 Jun 2010, 8:04 AM
I use class level observability on Ext.data.Connection to reset a buffered call do MyApp.doLogout

Ext.override(Function, {
createBuffered: function(buffer, scope){
var method = this,
task = this.task || (this.task = new Ext.util.DelayedTask()),
result = function(){
task.delay(buffer, method, scope, Ext.toArray(arguments));
result.callNow = method;
return result;


MyApp.doLogout = (function() {
// your logic here
}).createBuffered(<session timeout value in milliseconds>);

Then any call to MyApp.doLogout will set it to execute after the timeout.

So kick it off on page load, and also on return of every Ajax request (hence class observability on Connection)

25 Jun 2010, 3:28 AM
Hey thanks Animal. I'll start looking into the API along with your code above to see what its doing.