Authlogic: logged_in? depends on last_request_at
Authlogic, a popular authentication plugin for RoR, has its share of magic, some well documented, some less.
One thing that kept me busy yesterday was the absence of the logged_in? method on instances of the User class.
Turns out, authlogic, again, adapts its abilities depending on which columns the users table has. For the logged_in? method to exist, the column last_request_at must exist.
Now in the code there is a little bit of confusion, because in the authlogic lib file logged_in_status.rb there are actually two places dealing with this dependency:
def logged_in?
raise "Can not determine the records login state because\
there is no last_request_at column" if !respond_to?(:last_request_at)
!last_request_at.nil? && last_request_at > logged_in_timeout.seconds.ago
end
The exception should have brought me onto the right track, but, as it turns out, the instance methods themselves are only included, if the column last_logged_in exists, see the line
return if !klass.column_names.include?("last_request_at")
of the same file. So there you have it: no exception, just a silent absence of the method logged_in?.
Happy authenticating!
Sorry, comments are closed for this article.