- Similar to the unix
whocommand but for ruby web applications usingwardenfor authentication. - Gets list of users who are (most likely) logged in.
# Assuming the authentication model is `User`
Warden::Who.list(User)
# returns list of user_ids who are currently logged in- The list of logged-in user ids is stored in redis.
- Then just gem install
gem install warden-who- Set up with the initializer code (ie. in
config/initializersif Rails application)
require "warden-who"
Warden::Who.set_cache(Redis.new(ENV["REDIS_URL"])- This gem plugs into the
wardenafter_authenticationandbefore_logouthooks to track users who are currently logged in. - As such, there will be edgecases where this gem will miss such as:
- users clearing cookies
- users logging in/out on multiple devices