title: Devise multiple pathes for one model
body: <p>I want to have two different routes for devise: </p>
  
  <ul>
  <li>localhost:3000/login - standart devise auth</li>
  <li>localhost:3000/api/login - auth for api calls using another, not standart controller <strong>/api/sessions_controller</strong></li>
  </ul>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code>devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout' }  
  namespace :api, defaults: { format: :json } do
    devise_for :users,
               path: '',
               defaults: { format: :json },
               path_names: {
                 sign_in: 'login',
                 sign_out: 'logout',
                },
                controllers: { sessions: 'api/sessions' }
  end
  </code></pre>
  
  <p><strong>rails routes | grep sessio</strong></p>
  
  <pre><code>new_user_session         GET     /login(.:format)  devise/sessions#new
  user_session             POST    /login(.:format) devise/sessions#create
  destroy_user_session     DELETE  /logout(.:format) devise/sessions#destroy
  new_api_user_session     GET     /api/login(.:format) api/sessions#new {:format=&gt;:json}
  api_user_session         POST    /api/login(.:format) api/sessions#create {:format=&gt;:json}
  destroy_api_user_session DELETE  /api/logout(.:format) api/sessions#destroy {:format=&gt;:json}
  </code></pre>
  
  <p><strong>api/sessions_controller.rb</strong></p>
  
  <pre><code>class Api::SessionsController &lt; Devise::SessionsController
  skip_before_action :verify_authenticity_token
  skip_before_action :authenticate_user!
  
  respond_to :json
  
  private
  
  def respond_with(resource, _opts = {})
    render json: resource
  end
  
  def respond_to_on_destroy
    head :no_content
  end
  end
  </code></pre>
  
  <p>That code looks fine for me, but when i try to send POST-request to my <strong>localhost:3000/api/login</strong> with auth credentials it returns error:</p>
  
  <blockquote>
    <p>{"error":"You need to sign in or sign up before continuing."}</p>
  </blockquote>
  
  <p>If i comment out my default devise routes and move api routes from api namespace everything works fine, post-request return me json with resource:
  <strong>routes.rb</strong></p>
  
  <pre><code>#devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout' }  
  devise_for :users,
               path: 'api',
               defaults: { format: :json },
               path_names: {
                 sign_in: 'login',
                 sign_out: 'logout',
                },
                controllers: { sessions: 'api/sessions' }
  
  namespace :api, defaults: { format: :json } do
    ...
  end
  </code></pre>
  
  <p>Why that happened? What i'm missing?</p>