Reputation: 4271
I'm on Heroku. Is there a way to log into the console and log out a specific user so they must sign in again? Using Devise.
Upvotes: 1
Views: 3149
Reputation: 13923
I found that just updating the password would sign the user out.
user = User.find <x>
user.password = "<new password>"
user.save
On refreshing your page, you will see that the user is logged out. And if you were to set it to what it was before, the user still remains logged out.
Upvotes: 1
Reputation: 61
Let's assume you have deployed some critical fix and need to logout all users, you can put some black magic into your application_controller.rb, but make sure PM doesn't see it because he will burn you on fire ;)
before_action logout_users, if: :user_signed_in?
def logout_users
expire_date = DateTime.strptime(last_deploy_time)
sign_out current_user if current_user.current_sign_in_at < expire_date
end
Upvotes: 0
Reputation: 19249
Warden stores the user id and the encrypted password in the users cookie and signs it. That means changing their password will sign them out.
Note that if you copy their encrypted password and put it back later, and they still have the cookie, they will be back in as nothing had happened.
If you can't change the password, I'm afraid you can't do it without some black magic (eg. put a piece of code that will only run on their user id and log them out).
Upvotes: 3