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

前端 未结 7 1734
一个人的身影
一个人的身影 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:17

    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.

提交回复
热议问题