V
V
Vayladion Gognazdiak2019-04-18 10:43:08
Ruby on Rails
Vayladion Gognazdiak, 2019-04-18 10:43:08

Why does devise_token_auth break vanilla devise routes?

Bonjorno bambini! Life-giving beer to all after deep blue friday!
I have a question to ask you.
There is a rails5 add-on that uses devise and devise_token_auth.
Devise is used on the face in conjunction with omniauth, omniauth-google-oauth2 and omniauth-facebook.
token-auth for api.
Actually routing:

scope module: 'api' do
  namespace :v1 do
    mount_devise_token_auth_for 'User', at: 'auth'
  end
end

devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }, as: 'auth'
resources :users

This gives us the following routes:
=========================TOKEN AUTH=======================================
 new_v1_user_session GET        /v1/auth/sign_in(.:format)                           devise_token_auth/sessions#new
                           v1_user_session POST       /v1/auth/sign_in(.:format)                           devise_token_auth/sessions#create
                   destroy_v1_user_session DELETE     /v1/auth/sign_out(.:format)                          devise_token_auth/sessions#destroy
                      new_v1_user_password GET        /v1/auth/password/new(.:format)                      devise_token_auth/passwords#new
                     edit_v1_user_password GET        /v1/auth/password/edit(.:format)                     devise_token_auth/passwords#edit
                          v1_user_password PATCH      /v1/auth/password(.:format)                          devise_token_auth/passwords#update
                                           PUT        /v1/auth/password(.:format)                          devise_token_auth/passwords#update
                                           POST       /v1/auth/password(.:format)                          devise_token_auth/passwords#create
               cancel_v1_user_registration GET        /v1/auth/cancel(.:format)                            devise_token_auth/registrations#cancel
                  new_v1_user_registration GET        /v1/auth/sign_up(.:format)                           devise_token_auth/registrations#new
                 edit_v1_user_registration GET        /v1/auth/edit(.:format)                              devise_token_auth/registrations#edit
                      v1_user_registration PATCH      /v1/auth(.:format)                                   devise_token_auth/registrations#update
                                           PUT        /v1/auth(.:format)                                   devise_token_auth/registrations#update
                                           DELETE     /v1/auth(.:format)                                   devise_token_auth/registrations#destroy
                                           POST       /v1/auth(.:format)                                   devise_token_auth/registrations#create
                  new_v1_user_confirmation GET        /v1/auth/confirmation/new(.:format)                  devise_token_auth/confirmations#new
                      v1_user_confirmation GET        /v1/auth/confirmation(.:format)                      devise_token_auth/confirmations#show
                                           POST       /v1/auth/confirmation(.:format)                      devise_token_auth/confirmations#create
                    v1_auth_validate_token GET        /v1/auth/validate_token(.:format)                    devise_token_auth/token_validations#validate_token
                           v1_auth_failure GET        /v1/auth/failure(.:format)                           devise_token_auth/omniauth_callbacks#omniauth_failure
                                           GET        /v1/auth/:provider/callback(.:format)                devise_token_auth/omniauth_callbacks#omniauth_success
                                           GET|POST   /omniauth/:provider/callback(.:format)               devise_token_auth/omniauth_callbacks#redirect_callbacks
                          omniauth_failure GET|POST   /omniauth/failure(.:format)                          devise_token_auth/omniauth_callbacks#omniauth_failure
                                           GET        /v1/auth/:provider(.:format)                         redirect(301)


======================WЫEB-МОРДА==========================================


                     new_auth_user_session GET        /users/sign_in(.:format)                             devise/sessions#new
                         auth_user_session POST       /users/sign_in(.:format)                             devise/sessions#create
                 destroy_auth_user_session DELETE     /users/sign_out(.:format)                            devise/sessions#destroy
                    new_auth_user_password GET        /users/password/new(.:format)                        devise/passwords#new
                   edit_auth_user_password GET        /users/password/edit(.:format)                       devise/passwords#edit
                        auth_user_password PATCH      /users/password(.:format)                            devise/passwords#update
                                           PUT        /users/password(.:format)                            devise/passwords#update
                                           POST       /users/password(.:format)                            devise/passwords#create
             cancel_auth_user_registration GET        /users/cancel(.:format)                              devise/registrations#cancel
                new_auth_user_registration GET        /users/sign_up(.:format)                             devise/registrations#new
               edit_auth_user_registration GET        /users/edit(.:format)                                devise/registrations#edit
                    auth_user_registration PATCH      /users(.:format)                                     devise/registrations#update
                                           PUT        /users(.:format)                                     devise/registrations#update
                                           DELETE     /users(.:format)                                     devise/registrations#destroy
                                           POST       /users(.:format)                                     devise/registrations#create
                new_auth_user_confirmation GET        /users/confirmation/new(.:format)                    devise/confirmations#new
                    auth_user_confirmation GET        /users/confirmation(.:format)                        devise/confirmations#show
                                           POST       /users/confirmation(.:format)                        devise/confirmations#create
auth_user_google_oauth2_omniauth_authorize GET|POST   /omniauth/google_oauth2(.:format)                    callbacks#passthru
 auth_user_google_oauth2_omniauth_callback GET|POST   /omniauth/google_oauth2/callback(.:format)           callbacks#google_oauth2
     auth_user_facebook_omniauth_authorize GET|POST   /omniauth/facebook(.:format)                         callbacks#passthru
      auth_user_facebook_omniauth_callback GET|POST   /omniauth/facebook/callback(.:format)                callbacks#facebook

Although, according to the logic for the web, the callback routes should look like this:
auth_user_google_oauth2_omniauth_authorize GET|POST   /users/auth/google_oauth2(.:format)                  callbacks#passthru
 auth_user_google_oauth2_omniauth_callback GET|POST   /users/auth/google_oauth2/callback(.:format)         callbacks#google_oauth2
     auth_user_facebook_omniauth_authorize GET|POST   /users/auth/facebook(.:format)                       callbacks#passthru
      auth_user_facebook_omniauth_callback GET|POST   /users/auth/facebook/callback(.:format)              callbacks#facebook

In this regard, the question is - how to prevent devise_token_auth from breaking routes?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question