# Auto-logout after 15 minutes

**URL:** <https://www.ruby-forum.com/t/auto-logout-after-15-minutes/177237>\
**Category:** Rails\
**Created:** [October 13, 2009, 11:24pm UTC](https://www.ruby-forum.com/t/auto-logout-after-15-minutes/177237 "2009-10-13T23:24:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [October 13, 2009, 11:24pm UTC](https://www.ruby-forum.com/t/auto-logout-after-15-minutes/177237/1 "2009-10-13T23:24:11Z")

</div>

Hi There,

Im going through the ruby on rails tutorial ‘Railsspace’ at the  
moment.

There is a :remember\_me function that allows a cookie to be set at  
login to remember the user. See below:

if @user.remember\_me == “1”  
cookies[:remember\_me] = { :value =\> “cookie name”,  
:expires =\> 2.minutes.from\_now }  
user.authorization\_token = Digest::SHA1.hexdigest(  
“#{user.username}:  
#{user.password}”)

user.save!  
cookies[:authorization\_token] = {  
:value =\> user.authorization\_token,  
:expires =\> 2.minutes.from\_now }  
else  
cookies.delete(:remember\_me)  
cookies.delete(:authorization\_token)

When i look in safari’s preferences, I can see that the cookie is set.  
Agfter the 2 mins, I refresh the web page, and…

- Safari removes the cookies, but the user still looks logged in.

Is there a way to amend this to ensure that say, after 15 mins, the  
user is automatically logged out.

Can anyone help?

Many Thanks

---

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [October 13, 2009, 11:38pm UTC](https://www.ruby-forum.com/t/auto-logout-after-15-minutes/177237/2 "2009-10-13T23:38:14Z")

</div>

Hi,

Use the “session-timeout” plugin.

> **[GitHub - lukeredpath/session-timeout: A simple dynamic session expiry/timeout...](https://github.com/lukeredpath/session-timeout/)**
>
> A simple dynamic session expiry/timeout plugin for Rails - GitHub - lukeredpath/session-timeout: A simple dynamic session expiry/timeout plugin for Rails

Example:

session\_times\_out\_in 15.minutes, :after\_timeout =\> :do\_something

Good luck.

_Johalf Farina_  
+55 (51)8487 1402

Twitter [http://twitter.com/johalf](http://twitter.com/johalf)  
Working with  
Rails[http://www.workingwithrails.com/person/15914-johalf-farina](http://www.workingwithrails.com/person/15914-johalf-farina)  
www.fande.com.br [http://fande.com.br](http://fande.com.br)

On Tue, Oct 13, 2009 at 6:22 PM, RubyonRails\_newbie \<
