What is last_sign_in_at used for in Devise?

John Bachir picture John Bachir · Jul 6, 2015 · Viewed 8.6k times · Source

A standard User column in Devise is last_sign_in_at, which holds the previous value of current_sign_in_at when current_sign_in_at is updated.

Does last_sign_in_at have any utility for Devise's core functionality or Module functionality, or is it just there as a general convenience?

Answer

IAmNaN picture IAmNaN · Feb 19, 2017

last_sign_in_at is the date and time the user signed in before their current session, which is current_sign_in_at. It will be nil if they haven't signed in or this is their first session.

A better name might have been previous_sign_in_at because it is not the time they signed in last (the current one), it's the time before that.

It might be helpful to illustrate its use: After sign in, if updated_at on your Terms & Conditions page is newer than the user's last_sign_in_at then redirect them to a terms acceptance page.

As with most attributes in the Trackable module, it is not used internally to Devise although it is maintained by it.