-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
# You need to override respond
def respond
if warden_message == :unconfirmed
Rails.logger.debug "redirect"
return redirect
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 CustomFailureApp error, and you've put the CustomFailureApp 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')