如何从 Rails 控制台注销设计用户? [英] How can I sign out a devise user from the Rails console?
问题描述
我的设计用户是database_authenticable"和token_authenticable".我已经尝试从控制台为该用户删除数据库中的authentication_token"字段,但他们似乎仍然能够使用现有的身份验证令牌.删除用户完全可行,但我不想走那么远.
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.
为了清楚起见.我想使用 rails 控制台 来注销用户.即运行 rails console
然后是一些命令.
for clarity. I want to use the rails console to sign out a user. i.e. run rails console
and then some command.
推荐答案
Devise 提供了帮助方法来做这些事情:
Devise provides helper methods to do these things:
user = User.find(params[:id])
sign_in user
sign_out user
希望这会有所帮助.
这篇关于如何从 Rails 控制台注销设计用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!