So, I have some current_user method, which takes ID from cookie's auth_token
, and I want cookie be to deleted when window with site has been closed.
cookies[:auth_token] = @user.auth_token
What I have to add?
So, I have some current_user method, which takes ID from cookie's auth_token
, and I want cookie be to deleted when window with site has been closed.
cookies[:auth_token] = @user.auth_token
What I have to add?
Actually, if you set a cookie without giving an expiration date, it is only retained until the browser is closed. (Which can mean the program itself, not just a window or a tab.)
An expiration in the past will delete the cookie immediately.
From Thread: http://www.ruby-forum.com/topic/94682
@Joe Half Face, If it helps you, please mark it useful.
I once implemented a similar thing. For security purposes we had to automatically log the user out when they navigate away from the page. The solution looked like this:
beforeunload
event handler.beforeunload
event handler waits for its completion.