'In Devise I can not check if user was authenticated or not when active_for_authentication? returns false. How can I do that?

My Rails application uses Devise for authentication. My User model has active_for_authentication? which checks for user status attribute and returns true or false for different statuses (active or suspended). My application also has a before_action hook which assigns I18n.locale to the User#language attribute value.

The problem is the following: every time I try to access either current_user or user_signed_in? Devise helper for user language detection purposes the Devise runs active_for_authentication? method. And if that method returns false the Devise halts the entire HTTP request (internally it calls throw :warden, ...) and renders its own error. It turns out that I'm unable to access authenticated but suspended user instance in my code with Devise.

I want suspended users to see error messages in their language like active ones. How can I achieve that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source