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

joseph.hainline picture joseph.hainline · Mar 9, 2015 · Viewed 28.4k times · Source

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.

Answer

Ankit Samarthya picture Ankit Samarthya · Mar 9, 2015

Devise provides helper methods to do these things:

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

Hope this helps.