Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does devise have 'callback'?

After a user log in, I want to manually log this event and increment a counter column in database.

Is there something like after_login in Devise? Just as ActiveRecord's before_save?

like image 361
Lai Yu-Hsuan Avatar asked Jul 10 '12 08:07

Lai Yu-Hsuan


1 Answers

Devise uses Warden behind the scenes and Warden supplies you with a number of callbacks:

https://github.com/hassox/warden/wiki/callbacks

Have a look at the after_authentication callback. That's what you are looking for.

Code:

Warden::Manager.after_authentication do |user, auth, opts|
  # your code here.. 
end

You can simply create a new initializer file and put the code there. (Like /config/initializers/warden_callbacks.rb)

like image 143
Tigraine Avatar answered Sep 29 '22 23:09

Tigraine