Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise call backs

Tags:

Does devise have call backs when a user signs in and out?

This is what I came up with:

Warden::Manager.after_authentication do |user,auth,opts|   user.update_attribute(:currently_signed_in, true) end  Warden::Manager.before_logout do |user,auth,opts|   user.update_attribute(:currently_signed_in, false) end 

This is what I came with to track users that are currently signed in.

like image 779
thenengah Avatar asked Jan 31 '11 10:01

thenengah


2 Answers

I'm no expert but I believe the callbacks (hooks) are at the Warden level (Devise is built on top of Warden).

after_set_user and before_logout in Warden should do the trick for you but there are other options listed in Warden::Hooks

like image 150
srboisvert Avatar answered Sep 18 '22 18:09

srboisvert


You can overwrite sign_in in your application controller like this

 def sign_in(*args)    super(*args)     # do whatever you want here     token = current_user.authentications.where(provider: "facebook").first.token     facebook = Koala::Facebook::API.new(token)     session[:facebook] = facebook end 
like image 43
Moustafa Samir Avatar answered Sep 19 '22 18:09

Moustafa Samir