ruby on rails - intercept devise active_for_authentication error message -
i trying implement 'disable user' functionality. various source have read possible following in user.rb
def active_for_authentication? super && disabled_at.blank? end def inactive_message 'your account has been disabled.' end
this works fine, after user has been disabled signs him out , points sign_in page , shows correct inactive message.
however when user tries sign in(via ajax) following happens:
request url:http://localhost:3000/users/sign_in request method:post status code:302 moved temporarily
but in server console actually
completed 401 unauthorized in 132ms
this sessions_controller.rb
def create self.resource = warden.authenticate!(scope: resource_name, recall: "#{controller_path}#failure_with_ajax") sign_in(resource_name, resource) trial_mode_days_left?(resource) render json: { redirect: root_path }, status: :ok end def failure_with_ajax render json: { error: t('devise.failure.invalid') }, status: :unprocessable_entity end
the problem when user disabled, failure_with_ajax never called, working when entered credentials wrong. don't know why recall isnt triggered when active_for_authentication false, , how pass inactive_message user on front end.
this because warden.authenticate when calls active_for_authentiction not throw failure response options. calls super method failure , option given "recall" not thrown. found patch it. have override devise. solution here
Comments
Post a Comment