How can I sign out a devise user from the Rails console?

devise sign out user from controller
devise sign out all users
devise rails
devise rails console
devise sign in
devise create user
rails devise tutorial
rails g devise:install

My devise users are "database_authenticatable" and "token_authenticatable". I've tried deleting the "authentication_token" field in the database for that user from the console, but they still seem to be able to use their existing auth token. Deleting the user entirely works, but I don't want to go that far.

Edit: for clarity. I want to use the rails console to sign out a user. i.e. run rails console and then some command.


Devise provide helper methods to do these things.

user = User.find(params[:id])
sign_in user
sign_out user

Hope this helps.

How can I sign out a devise user from the Rails console?, Deleting the user entirely works, but I don't want to go that far. Edit: for clarity. I want to use the rails console to sign out a user. i.e. run rails  rails console >>> user = User.find (1) >>> user.admin = true >>> user.save This pattern is common, and is useful in apps where site administrators need to perform tasks in common with regular users. In some other kinds of apps, the site administrators may need perform a completely different set of tasks to regular users.


If you are using Devise you could use the below in your rails console. This works perfect for me as in my app if you are using only 1 session per user account. I am storing my sessions in redisDB.

user = User.first
user.update_attributes(unique_session_id: "")

All I had to do was clear my users unique_session_id for that user and rails kicks the user out of the session.

But for multiple sessions for the same User account this does not work.

If you want to clear all user sessions you can do the below from terminal

rake db:sessions:clear

[Help] Devise logout specific user from console : rails, How can I sign out a devise user from the Rails console? >> ApplicationController.allow_forgery_protection = false >> app.post('/users/​sign_in', {"user"  User accounts of several types are the common functionality of web applications. Ruby on Rails ecosystem provides several helpful gems: Devise for user authentication, CanCanCan for authorization, and RailsAdmin for admin panels. The following article has been moved here from codepany.com blog. The content was updated to the newest Ruby and Rails versions, but it’s still compatible …


You may be able to use the helpers that others have mentioned after including the necessary module:

include Devise::Controllers::SignInOut

source: Module: Devise::Controllers::SignInOut

There's also another SO question where someone shares a method that doesn't involve using Devise helpers here.

Devise wiki, Hi, is there any way to log out some specific users (not current_user) through the console? I am using devise 1.5.4 with rails 3.0.20. Thanks. 12 comments. share. The Rails console doesn't interact directly with request objects, nor with Devise, so it won't give you any of those methods (similarly, it won't give you really any controller or view logic). A thing you can do, though, is stick a byebug in one of your controller actions, then start your rails server.


I'm not a fan of the sign_out @user pattern because, at least for the devise version I'm using, that signs out the current user, regardless of the argument I pass it. If you're storing sessions in your database then you can do this:

@user.update_attributes(current_sign_in_token: "")

TBH I don't think that's the best way to do it, but it's the best way I've seen in my own research.

Module: Devise::Controllers::SignInOut, Sign out all active users or scopes. #signed_in?(scope = nil) ⇒ Boolean. Return true if the given scope is signed in session. Devise works with multiple Ruby and Rails versions, and ActiveRecord and Mongoid ORMs, which means you can run the test suite with some modifiers: DEVISE_ORM and BUNDLE_GEMFILE. DEVISE_ORM Since Devise support both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.


Seems attribute tokens save sessions:

user.tokens = nil
user.save

Rails: Kick a logged in user(devise) out of his session: solved , The user session cannot be accessed by other users (like from the rails console or database level). The closest i thought I came is to trick the  Updating a rails password via the rails console May 2, 2014 I’m in the process of learning ruby on rails and it’s going amazingly, plus Michael Hartl as a great teacher, I strongly suggest going through his screencasts.


Adding Authentication with Devise, Run the following command in the terminal. rails g devise: rails g devise user rails db:migrate. Coach: Explain first user. Devise creates all the code and routes required to create accounts, log in, log out, etc. Add sign-up and login links. Rails add user in rails console Raw This is quite a 'classic' problem and the immediate thought ("just do it mySQL") doesn't work here because of the need to have the rails piece that encodes a password that is entered.


Devise: Invalidating all sessions for a user, Rails has a default mechanism to store the session in the CookieStore . So if you want to logout a user AND invalidate old session cookies you need to reset  Creating User and Admin Model using Devise Rails 4.0 In this tutorial I will show you how to install Devise. I decided to make this tutorial because it is hard to find a good resource for installing Devise on Rails 4.0.


Deleting the user entirely works, but I don't want to go that far. Edit: for clarity. I want to use the rails console to sign out a user. i.e. run rails  Rails will freak out, and say "I literally do not know what you want me to do, because what you want me to do does not exist." There are good reasons for why destroy_user_session_path doesn't work with GET, but that's a longer conversation.