lynndylanhurley / lynndylanhurley/devise_token_auth

Mount in multiple namespaces - not supported?

Open
#1,235 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
3.6k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi there!

The problem I am having hopefully is a simple one. I am attempting to mount devise_token_auth a second time in the `v2` namespace, but cannot get it to allow me to do so. It is pretty important since we are starting the rebuild of our API and need auth changed a bit. Is this a bug or a known constraint of the library?

##### Routes
```
scope '/v2', module: :v2, constraints: ApiConstraints.new(version: 2, default: false), defaults: { format: :jsonapi } do
mount_devise_token_auth_for 'User', at: 'auth', controllers: {
sessions: 'v2/sessions',
omniauth_callbacks: 'v2/devise_token_auth/omniauth_callbacks'
}

resources :offers
end

scope '/v1', module: :v1, constraints: ApiConstraints.new(version: 1, default: false) do
mount_devise_token_auth_for 'User', at: 'auth', controllers: {
sessions: 'v1/sessions',
omniauth_callbacks: 'v1/devise_token_auth/omniauth_callbacks'
}
resources :accounting_codes, only: [:index, :show]
end
```

#### Gem Details
* devise (4.4.3)
* devise_token_auth (0.2.0)

#### Stack Trace

```
/Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:584:in `add_route': Invalid route name, already in use: 'new_user_session' (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1933:in `add_route'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1904:in `decomposed_match'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1902:in `block in decomposed_match'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1517:in `block (2 levels) in member'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1833:in `path_scope'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1517:in `block in member'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1713:in `with_scope_level'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1511:in `member'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1902:in `decomposed_match'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1873:in `block in map_match'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1871:in `each'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1871:in `map_match'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1610:in `match'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:743:in `map_method'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:704:in `get'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:379:in `block in devise_session'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1290:in `block (2 levels) in resource'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1721:in `block in resource_scope'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:894:in `controller'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1721:in `resource_scope'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1289:in `block in resource'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1713:in `with_scope_level'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1287:in `resource'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:378:in `devise_session'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:268:in `block (4 levels) in devise_for'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:268:in `each'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:268:in `block (3 levels) in devise_for'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:472:in `with_devise_exclusive_scope'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:267:in `block (2 levels) in devise_for'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:370:in `block in devise_scope'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1008:in `block in constraints'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:879:in `scope'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:1008:in `constraints'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:369:in `devise_scope'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:266:in `block in devise_for'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:242:in `each'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:242:in `devise_for'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/devise_token_auth-0.2.0/lib/devise_token_auth/rails/routes.rb:30:in `mount_devise_token_auth_for'
from /Users/casey/Sites/aeg/aeg-prince-api/config/routes.rb:31:in `block (2 levels) in '
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:879:in `scope'
from /Users/casey/Sites/aeg/aeg-prince-api/config/routes.rb:30:in `block in '
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:414:in `draw'
from /Users/casey/Sites/aeg/aeg-prince-api/config/routes.rb:3:in `'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `block in load'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:41:in `each'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:41:in `load_paths'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:20:in `reload!'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:30:in `block in updater'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.1/lib/active_support/file_update_checker.rb:83:in `execute'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:10:in `execute'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/finisher.rb:130:in `block in '
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `instance_exec'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `run'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `call'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
from /Users/casey/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/initializable.rb:60:in `run_initializers'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application.rb:361:in `initialize!'
from /Users/casey/Sites/aeg/aeg-prince-api/config/environment.rb:5:in `'
from config.ru:3:in `require_relative'
from config.ru:3:in `block in '
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/builder.rb:55:in `instance_eval'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/builder.rb:55:in `initialize'
from config.ru:in `new'
from config.ru:in `'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/builder.rb:49:in `eval'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/builder.rb:49:in `new_from_string'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/server.rb:319:in `build_app_and_options_from_config'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/server.rb:219:in `app'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:27:in `app'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/server.rb:354:in `wrapped_app'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:89:in `log_to_stdout'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:51:in `start'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:142:in `tap'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:142:in `perform'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/command/base.rb:65:in `perform'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/command.rb:46:in `invoke'
from /Users/casey/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/commands.rb:18:in `'
from bin/rails:4:in `require'
from bin/rails:4:in `'
```

Contributor guide

Open the contributing guide

Research direction

Start with the duplicated mount_devise_token_auth_for calls in config/routes.rb and follow the trace into devise_token_auth/rails/routes.rb and Devise's devise_for handling. Reproduce the route-loading failure and determine whether multiple namespaces are supported; done requires a documented resolution or a focused regression case for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.