Skip to content

How To: Redirect to a specific page when the user email is not confirmed?

Seoung Ho Jeong edited this page Nov 28, 2019 · 3 revisions

If a user is not confirmable you can redirect to a specific page.

This example shows how to redirect to unconfirmed email information page when unconfirmed user want's to login.


# written on lib/devise/custom_failure_app.rb
class CustomFailureApp < Devise::FailureApp
  def redirect_url
    if warden_message == :unconfirmed
      return email_confirm_path(email: params[:user][:email])
    end
    super
  end

end

And add the following in config/initializers/devise.rb:

  config.warden do |manager|
    manager.failure_app = CustomFailureApp
  end

If you're getting an uninitialized constant CustomFailure error, and you've put the CustomFailure class under your /lib directory, make sure to autoload your lib files in your application.rb file, like below

  config.autoload_paths << Rails.root.join('lib').join('devise')
Clone this wiki locally