ruby-on-railsauthenticationdevisewarden

Devise: rememberable means that last_sign_in_at is not updated by trackable


I have being using Devise, and relying on last_sign_in_at of the user model to work out if my customers have not returned within X days. However, I recently discovered that last_sign_in_at is only updated when an actual form log in event occurs, as opposed to when a user is logged in automatically due to the inclusion of rememberable.

If want to ensure that last_sign_in_at is updated each time a user logs in (a new browser session), regardless of whether they used a form to log in or were automatically logged in by the rememberable cookie, how would I go about doing this in a Devise-compatible way?


Solution

  • The trackable hook is from Warden's after_set_user hook -- what you could do to easily remedy this is set a before_filter to call sign_in.

    This could be optimized, but test to see if using

    before_filter proc{ sign_in(current_user, :force => true) }
    

    updates the last_signed_in_at timestamp.