title: Rails Sign in using devise to authenticate from two db tables
body: <p>I have 2 database tables namely <code>coreteam</code> and <code>user</code>. Both the models are configured with devise.
  For now to sign in for core team my API is: <code>localhost:3000/api/v1/core_teams/sign_in</code> with following request data.</p>
  
  <pre><code>{ 
    "core_team": {
      "email": "ba+admin@gmail.com",
      "password": "Password21"
    }
  }
  </code></pre>
  
  <p>And the API for users to sign in is: <code>localhost:3000//api/v1/users/sign_in</code>
  with the following request data.</p>
  
  <pre><code>{
    "user": {
      "email": "ba+user@gmail.com",
      "password": "Password20"
    }
  }
  </code></pre>
  
  <p>And following is my routes.rb file</p>
  
  <pre><code> Rails.application.routes.draw do
  
   root to: 'users#index'
  
  scope 'api/v1', defaults: { format: :json } do
   devise_for :core_teams, controllers: {
     sessions: 'api/v1/sessions',
     passwords: 'api/v1/passwords'
    }
  
   devise_for :users, controllers: {
     sessions: 'api/v1/sessions',
     invitations: 'api/v1/invitations',
     passwords: 'api/v1/passwords',
     registrations: 'api/v1/registrations'
    }
    end
  end
  </code></pre>
  
  <p>And I am using devise sessionscontroller to login. Only difference is the way I am rendering the data.</p>
  
  <p>My sessions_controller.rb is as follows: </p>
  
  <pre><code>module Api
   module V1
    class SessionsController &lt; Devise::SessionsController
     private
  
      def respond_with(resource, _opts = {})
        render json: resource
      end
  
      def respond_to_on_destroy
        head :no_content
      end
  
     end
    end
   end
  </code></pre>
  
  <p>Now my aim is to have only one API call to sign in using the same type of requests data. Reason to have two different user table is my app is kind of multi-tenanted and core team is outside of tenant and users are inside tenant.</p>
  
  <p><a href="https://i.stack.imgur.com/tJWBz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tJWBz.png" alt="CoreTeam and Tenant Architecture"></a></p>