Skip to content

Ensure that devise will update a flag/timestamp on the model whenever a user is authenticated.

License

Notifications You must be signed in to change notification settings

brunoocasali/devise_last_seen

Repository files navigation

devise_last_seen

This devise extension, will ensure that devise will update a flag/timestamp on the model whenever a user is set. With this kind of feature you could show in your views something like last seen 3 weeks ago or last seen 2 minutes ago.

ruby gem Test Coverage Maintainability

Installation

You know, add this line to your application's Gemfile:

gem 'devise_last_seen'

And then execute:

$ bundle

Usage

In your model, add :lastseenable module as such:

# app/models/user.rb

class User < ApplicationRecord
  devise :database_authenticable, ..., :lastseenable
end

Generate a rails migration to add the column to your devise model:

bundle exec rails g migration add_last_seen_to_users last_seen:datetime
class AddLastSeenToUsers < ActiveRecord::Migration[6.1]
  def change
    add_column :users, :last_seen, :datetime
  end
end

Configuration

Besides the column requirement you don't need customizations, but if you want to...

# config/initializers/devise.rb

Devise.setup do |config|
  ...

  # Interval (in seconds) to update the :last_seen_at_attribute attr
  # config.last_seen_at_interval = 5.minutes

  # Attribute who will be updated every time a user is set by the Warden's after_save callback
  # Remember to check if this column name is present on the devise model table.
  # config.last_seen_at_attribute = :last_seen
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rspec to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/brunoocasali/devise_last_seen. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the devise_last_seen project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Hall of fame!

This gem only could be done with help of other gems like:

About

Ensure that devise will update a flag/timestamp on the model whenever a user is authenticated.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks