【问题标题】:Using devise_token_auth with form auth将 devise_token_auth 与表单身份验证一起使用
【发布时间】:2015-05-17 11:43:00
【问题描述】:

我正在尝试允许在移动设备上使用令牌进行身份验证,同时仍将 Web 表单用于 Web 应用程序。我决定使用devise_token_auth。每当我尝试启动应用程序时,我都会收到错误消息,因为已经定义了会话路径。

错误

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

【问题讨论】:

    标签: ruby-on-rails ruby devise token rails-4-2-1


    【解决方案1】:

    试试这个:

    使用 devise_token_auth 生成器生成 Provider 资源

    $ rails g devise_token_auth:install Provider auth
    

    然后更改 config/routes.rb 以将此路由放置在 API 版本控制的命名空间中

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

    查看路线

    $ rake routes
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      • 2011-03-12
      • 1970-01-01
      • 2012-03-15
      • 2011-07-03
      相关资源
      最近更新 更多