# Automatic logout using AJAX

**URL:** <https://www.ruby-forum.com/t/automatic-logout-using-ajax/86562>\
**Category:** Rails\
**Created:** [February 23, 2007, 8:55am UTC](https://www.ruby-forum.com/t/automatic-logout-using-ajax/86562 "2007-02-23T08:55:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [February 23, 2007, 8:55am UTC](https://www.ruby-forum.com/t/automatic-logout-using-ajax/86562/1 "2007-02-23T08:55:50Z")

</div>

I’m considering implementing a Javascript timeout function on the client  
that would issue an AJAX-request to the server to do an automatic logout  
(by setting session[:user] to nil) after a certain time period (20  
minutes or so). The browser would be redirected to the login screen,  
and the user would have to log in again to continue.

Note that I don’t mean invalidate the session, but simply force the user  
to relogin after a certain time. I plan to remember the last action  
requested in the session so that I can redirect back to it after the  
user logs in again.

Has anyone implemented something like this, and if so, do you have any  
advice? I have a pretty good idea of how to proceed and I’m pretty sure  
this is doable. The only concern I have is potential nitty-gritty  
details on the client Javascript side of things.

Any reasons that I should not implement this, or other gotchas?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [February 23, 2007, 9:44am UTC](https://www.ruby-forum.com/t/automatic-logout-using-ajax/86562/2 "2007-02-23T09:44:53Z")

</div>

I don’t know AJAX too well, but I’m sure you’ll update this timer  
every time the user changes something. Won’t this be too hard?  
You’ll have to put a function like updateTimer() in all JS functions  
that may be called to update this.

On 2/23/07, Wes G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m considering…
> 
> …or other gotchas?
> 
> Thanks,  
> Wes

–  
Ramon Miguel M. Tayag
