Reputation: 14740
Is there a way to get a callback/ process some action when a user's session times out with Devise?
The plain old overriding the DeviseSessionsController doesn't work:
class SessionsController < Devise::SessionsController
def destroy
#do something
super
end
end
This only works when a user logs out, which makes sense since it doesn't seem like a controller is called on session timeout. Can someone help me out?
Upvotes: 3
Views: 3806
Reputation: 356
The issue is still up to date. The easiest solution I could muster for this is to override the timedout?
method in the User
model.
def timedout?(args)
retval = super(args)
if retval
# Do whatever you need to do here
end
retval
end
record.timedout?
gets called before signing out is trigger in the event of the timeout
https://github.com/heartcombo/devise/blob/main/lib/devise/hooks/timeoutable.rb#L27C5-L27C5
Upvotes: 0
Reputation: 14740
I found that doing Warden.before_logout was the best solution:
# app/models/user.rb
Warden::Manager.before_logout do |user, auth, opts|
#fdsafdsafdsa
end
Unfortunately, there doesn't seem to be any way to do this with pure Devise.
Upvotes: 6
Reputation: 2963
before_filter :destroy_custom, :only => [ :destroy ]
def destroy_custom
# Do your thang
end
I was able to do this on new method. I am guessing it is possible to do the same with destroy as well. The callback could be called inside the devise_custom or devise_custom itself could be the method where you want to execute something before destroy.
Upvotes: 0