Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devise login fail message

I followed this question Devise redirect after login fail and it works great, but I am getting a flash notice telling me that I need to login to continue, and the message I need is that the password or email is invalid. So I added the flash notice in the CustomFailure like this:

    class CustomFailure < Devise::FailureApp
  def redirect_url
    root_path
  end

  def respond
    if http_auth?
      http_auth
    else
      flash[:error] = I18n.t(:invalid, :scope => [ :devise, :failure ])
      redirect
    end
  end
end

and now it's showing me both messages, invalid password and unauthenticated, how can I eliminate the unauthenticated message?

like image 254
dcarey Avatar asked Apr 27 '26 09:04

dcarey


1 Answers

Devise does not set flash[:error], but flash[:alert] when the login fails, try to set this in your application.

You could also just overwrite the method Devise::FailureApp#i18n_message and have it return the message of your choosing:

class CustomFailure < Devise::FailureApp
  def redirect_url
    root_path
  end

  def i18n_message
    "Hello World" # you might go for something more elaborate here
  end
end
like image 89
yas4891 Avatar answered Apr 29 '26 23:04

yas4891



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!