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

前端 未结 7 1742
一个人的身影
一个人的身影 2021-02-06 21:53

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 co

7条回答
  •  花落未央
    2021-02-06 22:16

    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
    

提交回复
热议问题