0

I'm using the gem devise-token-auth which is working great.

At this moment, for signing up I use the original routes which is /api/v1/auth in my case :

# routes.rb
namespace :api do
  namespace :v1 do
    mount_devise_token_auth_for 'User', as: 'v1', 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

Now I want to change the default sign up URL for /api/v1/auth/signing_up for example, but when I add to my file the post line, even if rails routes returns what I want, I got an error :

# routes.rb
post "/auth/signing_up" => "users/registrations#create"

# rails routes
# Default route
api_v1_user_registrationPOST   /api/v1/auth(.:format)                  api/v1/users/registrations#create
# New created route
api_v1_auth_signing_up POST   /api/v1/auth/signing_up(.:format)       api/v1/users/registrations#create

# Error when POST
AbstractController::ActionNotFound (Could not find devise mapping for path "/api/v1/auth/signing_up".
ZazOufUmI
  • 3,212
  • 6
  • 37
  • 67
  • do you need the two sign up routes ?, have you tried `mount_devise_token_auth_for 'User', as: 'v1', at: 'auth/signing_up'` ? – fanta Aug 15 '18 at 14:45
  • No I don't necessary need to keep both. But I cannot reuse `mount_devise_token_auth_for` because I already used it once. I got `ArgumentError: Invalid route name, already in use` for all the paths (e.g. `new_api_v1_user_session`) – ZazOufUmI Aug 15 '18 at 14:49
  • don't use `mount_devise_token_auth_for` twice, do it in the line of code you already have: `mount_devise_token_auth_for 'User', as: 'v1', at: 'auth/signing_up', controllers: {...` – fanta Aug 15 '18 at 14:51
  • Unfortunately this change all my others routes to `/api/v1/auth/signing_up/sign_in` etc. and it's not what I want :/ – ZazOufUmI Aug 15 '18 at 15:07
  • have you tried using `devise_scope` ?, in the end, `devise_token_auth` gem uses `devise` gem. Take a look here https://github.com/lynndylanhurley/devise_token_auth/blob/master/lib/devise_token_auth/rails/routes.rb, and here https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes – fanta Aug 15 '18 at 15:56
  • No luck, it looks like we cannot add a new route for sign_up. Every time I encounter an error like the one mentioned in the original post. Thanks anyway ! – ZazOufUmI Aug 15 '18 at 20:00

1 Answers1

0

I am using this for different type of sign up and it is working good,

namespace :api, constraints: { format: 'json' } do
    namespace :v1 do
      devise_scope :user do
        post 'auth/teacher_sign_up', to: 'registration#teacher_sign_up'
      end

      devise_scope :user do
        post 'auth/student_sign_up', to: 'sessions#teacher_sign_up'
      end
    end
end