title: Add custom routes to devise returns 404 ActionNotFound
body: <p>I would like to create a new routes and method inside my Sessions Controller within Devise. I am using <a href="https://github.com/lynndylanhurley/devise_token_auth" rel="nofollow noreferrer">devise_token_auth</a></p>
  <p>Here is my original <code>routes.rb</code> for devise :</p>
  <pre><code>namespace :api do
      namespace :v1 do
        mount_devise_token_auth_for 'User', as: 'user', at: 'auth', controllers: {
          token_validations:  'api/v1/users/token_validations',
          confirmations:      'api/v1/users/confirmations',
          registrations:      'api/v1/users/registrations',
          passwords:          'api/v1/users/passwords',
          sessions:           'api/v1/users/sessions'
        }
      end
  end
  </code></pre>
  <p>which give me these classic routes :</p>
  <pre><code>new_api_v1_user_session GET          /api/v1/auth/sign_in(.:format)                   api/v1/users/sessions#new
  api_v1_user_session POST             /api/v1/auth/sign_in(.:format)                   api/v1/users/sessions#create
  destroy_api_v1_user_session DELETE   /api/v1/auth/sign_out(.:format)                  api/v1/users/sessions#destroy
  new_api_v1_user_password GET         /api/v1/auth/password/new(.:format)              api/v1/users/passwords#new
  edit_api_v1_user_password GET        /api/v1/auth/password/edit(.:format)             api/v1/users/passwords#edit
  ....
  </code></pre>
  <p>I have also inside my directory tree :</p>
  <pre><code>controllers
  -- api
  --- v1
  ----users
  ----- confirmations_controller.rb
  ----- passwords_controller.rb
  ----- registrations_controller.rb
  ----- sessions_controller.rb
  </code></pre>
  <p>Now I want to create a new custom method and routes inside the sessions controller for connected people. I want this new route : <code>/api/v1/auth/token</code></p>
  <p>So here is what I add to my routes :</p>
  <pre><code>devise_scope :user do   
      post '/auth/tokens', to: 'users/sessions#tokens'
  end
  </code></pre>
  <p>And the result when I do <code>rails routes</code>, which looks fine :</p>
  <pre><code>api_v1_auth_tokens POST   /api/v1/auth/tokens(.:format)                    api/v1/users/sessions#tokens
  </code></pre>
  <p>But in Postman when I call <code>POST {url}/api/v1/auth/tokens</code> I get the classic 404 error <strong>AbstractController::ActionNotFound</strong>.</p>
  <blockquote>
  <p>[Devise] Could not find devise mapping for path
  &quot;/api/v1/auth/tokens&quot;. This may happen for two reasons:</p>
  <ol>
  <li>You forgot to wrap your route inside the scope block. For example:</li>
  </ol>
  <p>devise_scope :user do
  get &quot;/some/route&quot; =&gt; &quot;some_devise_controller&quot;   end</p>
  <ol start="2">
  <li><p>You are testing a Devise controller bypassing the router.    If so,
  you can explicitly tell Devise which mapping to use:</p>
  <p>@request.env[&quot;devise.mapping&quot;] = Devise.mappings[:user]</p>
  </li>
  </ol>
  <p>Completed 404 Not Found in 1ms (ActiveRecord: 0.0ms | Allocations:
  110)</p>
  </blockquote>
  <p>But I am doing what the hint is telling me. What am I missing ?</p>