Method: DeviseController#require_no_authentication

Defined in:
app/controllers/devise_controller.rb

#require_no_authenticationObject (protected)

Helper for use in before_actions where no authentication is required.

Example:

before_action :require_no_authentication, only: :new

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/devise_controller.rb', line 102

def require_no_authentication
  assert_is_devise_resource!
  return unless is_navigational_format?
  no_input = devise_mapping.no_input_strategies

  authenticated = if no_input.present?
    args = no_input.dup.push scope: resource_name
    warden.authenticate?(*args)
  else
    warden.authenticated?(resource_name)
  end

  if authenticated && resource = warden.user(resource_name)
    set_flash_message(:alert, 'already_authenticated', scope: 'devise.failure')
    redirect_to (resource)
  end
end