Answer the question
In order to leave comments, you need to log in
How to make only one active session in devise?
I want to make sure that users can only have one active session. Those. if they come from another browser, then the previous session is closed and a new one is opened.
I thought about doing this by storing the session in the database (activerecord-session_store gem), but it turned out that the usual deletion of a record from the database does not kill the session and when the page is updated, a new record for the session is simply created in the database.
UPD: I forgot to restart the server :-( everything works. Deleting the session from the database works (i.e. the user logs out)
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then you need to make a restriction on one session for one user.
https://github.com/phatworx/devise_security_extension
In the Gemfile we write:
Run the migration generator:
Check the resulting migration. It should be like this:
class AddSessionLimitableToUsers < ActiveRecord::Migration
def change
add_column :users, :unique_session_id, :string, limit: 20
end
end
class User < ActiveRecord::Base
devise ..., :session_limitable
...
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question