user2954587
user2954587

Reputation: 4861

How to see active session in rails

How can I see the active sessions on my server? Is there a session table? I can't find it even if I do psql but from my reading there appears to be one. (docs and article)

I'm running Rails 5

Upvotes: 0

Views: 2939

Answers (2)

max
max

Reputation: 101811

Rails uses ActionDispatch::Session::CookieStore storage by default. Where the session is simply stored in an encrypted cookie on the client. The client passes the cookies back with each request and the rails unencrypts the cookie and populations the session hash.

How can I see the active sessions on my server?

You can't. The cookies are stored in the client. The server does not keep track of the clients that it issues cookies to. You would have to change to a different session storage which stores the session server side which is much slower.

There are several gems such as Active Record Session Store which was removed in Rails 4 which provide server side session storage.

But this is most likely not a good fix for the problem you are actually trying to solve as they also rely on a cookie to tie the client to a server side session storage.

Upvotes: 1

megas
megas

Reputation: 21791

You can try gem authie

Modify your User model to associate with session:

class User < ActiveRecord::Base
  has_many :sessions, :class_name => 'Authie::Session', :as => :user, :dependent => :destroy
end

Then you can query the sessions from database.

Upvotes: 0

Related Questions