Search code examples
ruby-on-railsrubydevisetokenrails-4-2-1

Using devise_token_auth with form auth


I'm trying to allow using on mobile devices to be authenticated using a token, while still using the webforms for the web application. I decided to use devise_token_auth. Whenever I try and start the application I get an error because a session path is already defined.

error

ArgumentError: Invalid route name, already in use: 'new_provider_session' 

config/routes.rb

mount_devise_token_auth_for 'Provider', at: 'api/v1/auth'
  devise_for :providers, controllers: {} do
    get 'providers/sign_in', to: 'web/sessions#new'
    delete 'providers/sign_out', to: 'web/sessions#destroy'
  end
  root to: 'web/welcome#welcome'

  devise_for :admins, controllers: {} do
    get 'admins/sign_in', to: 'web/sessions#new'
    delete 'admins/sign_out', to: 'web/sessions#destroy'
  end

Solution

  • try this:

    Generate the Provider resource with the devise_token_auth generator

    $ rails g devise_token_auth:install Provider auth
    

    then change the config/routes.rb for placing this routes inside the namespaces for API versioning

    namespace :api do
      namespace :v1 do
        mount_devise_token_auth_for 'Provider', at: 'auth'
      end
    end
    

    Check the routes

    $ rake routes