Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `authenticate_user!' when want to version my api #908

Closed
Mirigan opened this issue Jun 15, 2017 · 2 comments
Closed

undefined method `authenticate_user!' when want to version my api #908

Mirigan opened this issue Jun 15, 2017 · 2 comments

Comments

@Mirigan
Copy link

Mirigan commented Jun 15, 2017

Hello !
I have a huge problem, to day I wanted to versioning my api and my auth routes so I did this

namespace :api do
    namespace :v1 do
      mount_devise_token_auth_for 'User', as: 'v1', at: 'auth', controllers: {
        registrations:  'api/v1/user/registrations',
        passwords:      'api/v1/user/passwords',
        sessions:       'api/v1/user/sessions'
      }
    end

    namespace :v2 do
      mount_devise_token_auth_for 'User', as: 'v2', at: 'auth', controllers: {
        registrations:  'api/v2/user/registrations',
        passwords:      'api/v2/user/passwords',
        sessions:       'api/v2/user/sessions'
      }
    end
  end

but now I have an error undefined method 'authenticate_user!' and don't find solution.
Can someone have any idea ?

@gundogantekant
Copy link

gundogantekant commented Sep 26, 2017

As a quick work-around you can copy mount_devise_token_auth_for code to top, out of namespaces, since both versions will use the same credentials. Then you can have multiple mount_devise_token_auth_for entries with duplicate endpoints.

if you want to limit your routes to minimum, then you should use authenticate_v1_user! in your v1 controller and vice versa.

Also amitfriedman12 wrote in this issue using devise helper to your controllers might help.

include Devise::Controllers::Helpers

@zachfeldman
Copy link
Contributor

@gundogantekant thank you for your workaround! Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants