- 
                Notifications
    
You must be signed in to change notification settings  - Fork 76
 
Open
Description
I am trying to setup Rack Attack. And I came up with this bit:
class Rack::Attack
  # [...]
  self.throttled_responder = lambda do |request|
    # If the request is an API request, return JSON
    if request.path == '/users/sessions/verify' && request.env['action_dispatch.request.content_type'].symbol === :json
      [
        429, # status
        { 'Content-Type' => 'application/json' }, # headers
        [{
          error: 'Too many attempts. Please try again later.',
          retry_after: (request.env['rack.attack.match_data'] || {})[:period]
        }.to_json]
      ]
    else
      # For normal web requests, redirect to login page with flash message
      # Store the flash message in the session
      request.session['flash'] = {
        'alert' => 'Too many login attempts. Please try again later.'
      }
      [
        302, # status - redirect
        { 'Location' => '/users/sign_in', 'Content-Type' => 'text/html' }, # headers
        ['Redirecting...'] # body
      ]
    end
  end
end
Inertia complains:
All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.
{"error":"Too many attempts. Please try again later.","retry_after":60}
I started looking at the source but I have not figure out if InertiaRails can help with that.
Metadata
Metadata
Assignees
Labels
No labels