Help us understand the problem. What is going on with this article?

論理削除実装時のdevise対応

More than 1 year has passed since last update.

deviseによる認証を行っているrailsアプリで、kakurenbo-putiなんかで論理削除を実装しても、そのままではログインができてしまう。

論理削除したユーザーがログインしている場合は強制ログアウトし、ログインできないように、該当のモデルに下記のメソッドをオーバーライドすることで対応できる。
deleted_accountに、認証時のメッセージを登録する。

YourModel.ruby
  # ensure user account is active
  def active_for_authentication?
    super && !soft_destroyed_at
  end

  # provide a custom message for a deleted account
  def inactive_message
    !soft_destroyed_at ? super : :deleted_account
  end
config/locales/devise.ja.yml
ja:
  devise:
    failure:
      deleted_account: 'このアカウントは退会されています。'
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away