13

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?

John Bachir
  • 22,495
  • 29
  • 154
  • 227

2 Answers2

18

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.

IAmNaN
  • 10,305
  • 3
  • 53
  • 51
  • How to get the sign_out time in devise? – Arpit Agarwal Apr 27 '17 at 05:39
  • 1
    That is a different question and the trackable module will not help. You answer depends on what you want and what you have implemented already. You can create your own signed_out column in the database and set it in the sign out action of your controller sessions controller, or you can employ Devise's timeoutable module (if suitable) and examine the last_access attribute. – IAmNaN Apr 27 '17 at 16:14
  • Is it possible to have a last_sign_out_at ? If not is it possible to implement the same? – rahoolm Dec 11 '21 at 00:35
  • I think this is the same question Arpit asked. – IAmNaN Dec 13 '21 at 18:54
6

Looking through the source code, it seems to just be an attribute of Trackable -- meant purely as a general convenience.

https://github.com/plataformatec/devise/search?utf8=%E2%9C%93&q=last_sign_in_at

Additionally, the gemfile for Devise does not show anything that (I am guessing) would make use of that field.

So, just general convenience.

Mike Manfrin
  • 2,722
  • 2
  • 26
  • 41