Reputation: 133
I'd like to record when a user's session has timed out, using devise and :timeoutable
.
At the moment, :timeoutable
is working as expected and redirecting users to the login page after the specified period of inactivity, but in addition to this we'd like to log when this happens to help refine our timeout period.
(Obviously all sessions will time out unless the user explicitly logs out. We'll check the time since last activity to determine if it is a natural timeout or is more likely a result of us setting too short a timeout period.)
Is there an event that I can hook into or another way of detecting session timeout in the SessionController
?
Upvotes: 4
Views: 4271
Reputation: 18835
i've not seen any kind of hook, but you could just override the code in the timeoutable module that is used by devise:
module Devise
module Models
module Timeoutable
def timedout?(last_access)
# your custom code goes into this method
return false if remember_exists_and_not_expired?
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
end
end
end
end
Upvotes: 2
Reputation: 438
I think what you need to do is logging the time when the user clicks "Log out" explicitly. Because :timeoutable
has a default time period after which user session will automatically expire.
You can do logging "log out" activity by creating a Sessions_Controller
which inherits from Devise::SessionsController
. After logging current time, don't forget to do super
.
Upvotes: 0