1

I have a problem implementing the mount_devise_token_auth_for with api versions.
Let's say:

scope module: :v1, constraints: ApiConstraints.new(version: 1) do
    mount_devise_token_auth_for 'User', at: '/auth', skip: [  ],  controllers: {
       registrations:      'v1/users/registrations',
       sessions:           'v1/users/sessions'
    }
end

If I want to add v2 and mount the authentication at the same path like this:

scope module: :v2, constraints: ApiConstraints.new(version: 2, default: true) do
    mount_devise_token_auth_for 'User', at: '/auth', skip: [  ],  controllers: {
       registrations:      'v2/users/registrations',
       sessions:           'v2/users/sessions'
    }
end

It fails because the named routes helper for devise already exists with those names.
I could use namespace to deal with that, but we don't want the versions in the URI.
Please advise.
Thanks.

Anton
  • 540
  • 3
  • 13

1 Answers1

2

I forgot to post an answer to my question. I had to define v2 with

scope module: :v2, as: 'v2', constraints: ApiConstraints.new(version: 2, default: true) do
    mount_devise_token_auth_for 'User', at: '/auth', skip: [  ],  controllers: {
       registrations:      'v2/users/registrations',
       sessions:           'v2/users/sessions'
    }
end

The 'as: v2' part generates unique named routes helpers and everything works.

Anton
  • 540
  • 3
  • 13