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

Error ActionController::RoutingError: No route matches [GET] \"/omniauth/pincode\" #1058

Closed
Mohammed-Elias opened this issue Jan 4, 2018 · 1 comment

Comments

@Mohammed-Elias
Copy link

rails (5.1.4)
devise (4.3.0)
devise_token_auth (0.1.42)
ruby (2.4.0p0)

Gemfile

gem 'rails', '~> 5.1.4'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.7'
gem 'omniauth'
gem 'devise_token_auth'
gem 'twilio-ruby'

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails'
  gem 'shoulda-matchers'
  gem 'factory_bot_rails'
  gem 'faker'
end

I'm building a rails API, and through adding twilio-ruby gem to verify phone number of Customer, I added a new action to RegistrationsController after overriding it and this controller look like:

class Api::V1::Customers::RegistrationsController < DeviseTokenAuth::RegistrationsController

   def verify
     @customer = Customer.find_by(mobile_phone_number: request.headers[:mobile_phone_number])
     @customer.verify(request.headers[:pin_code])
     if @customer.verified
       render json: {message: 'You are verified'}
     else
       render json: {message: 'You have entered wrong pin code'}
     end
   end
end

and Customer model is

class Customer < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :omniauthable
  include DeviseTokenAuth::Concerns::User

  def verify(entered_pin)
    update(verified: true) if self.pin_code == entered_pin
  end
end

routes.rb file is

namespace 'api' do
  namespace 'v1' do

    mount_devise_token_auth_for 'Customer', at: 'customer/auth', controllers: {
      registrations: 'api/v1/customers/registrations',
      sessions: 'api/v1/customers/sessions'
    }
 end
end

then I add these lines underneath the above block in routes.rb to get the access to the new action verify:

devise_scope :customer do
  get "api/v1/customer/auth/pincode" => "api/v1/customers/registrations#verify"
end

After I ran rails routes, I got api_v1_customer_auth_pincode GET /api/v1/customer/auth/pincode(.:format) api/v1/customers/registrations#verify

and after running rails routes I got this:

new_api_v1_customer_session GET      /api/v1/customer/auth/sign_in(.:format)            api/v1/customers/sessions#new
api_v1_customer_session POST     /api/v1/customer/auth/sign_in(.:format)            api/v1/customers/sessions#create
destroy_api_v1_customer_session DELETE   /api/v1/customer/auth/sign_out(.:format)           api/v1/customers/sessions#destroy
new_api_v1_customer_password GET      /api/v1/customer/auth/password/new(.:format)       devise_token_auth/passwords#new
edit_api_v1_customer_password GET      /api/v1/customer/auth/password/edit(.:format)      devise_token_auth/passwords#edit
api_v1_customer_password PATCH    /api/v1/customer/auth/password(.:format)           devise_token_auth/passwords#update
                                PUT      /api/v1/customer/auth/password(.:format)           devise_token_auth/passwords#update
                                POST     /api/v1/customer/auth/password(.:format)           devise_token_auth/passwords#create
cancel_api_v1_customer_registration GET      /api/v1/customer/auth/cancel(.:format)             api/v1/customers/registrations#cancel
new_api_v1_customer_registration GET      /api/v1/customer/auth/sign_up(.:format)            api/v1/customers/registrations#new
edit_api_v1_customer_registration GET      /api/v1/customer/auth/edit(.:format)               api/v1/customers/registrations#edit
api_v1_customer_registration PATCH    /api/v1/customer/auth(.:format)                    api/v1/customers/registrations#update
                                PUT      /api/v1/customer/auth(.:format)                    api/v1/customers/registrations#update
                                DELETE   /api/v1/customer/auth(.:format)                    api/v1/customers/registrations#destroy
                                POST     /api/v1/customer/auth(.:format)                    api/v1/customers/registrations#create
new_api_v1_customer_confirmation GET      /api/v1/customer/auth/confirmation/new(.:format)   devise_token_auth/confirmations#new
api_v1_customer_confirmation GET      /api/v1/customer/auth/confirmation(.:format)       devise_token_auth/confirmations#show
                                POST     /api/v1/customer/auth/confirmation(.:format)       devise_token_auth/confirmations#create
api_v1_customer_auth_validate_token GET      /api/v1/customer/auth/validate_token(.:format)     devise_token_auth/token_validations#validate_token
api_v1_customer_auth_failure GET      /api/v1/customer/auth/failure(.:format)            devise_token_auth/omniauth_callbacks#omniauth_failure
                                GET      /api/v1/customer/auth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#omniauth_success
                                GET|POST /omniauth/:provider/callback(.:format)             devise_token_auth/omniauth_callbacks#redirect_callbacks
                                GET|POST /omniauth/failure(.:format)                        devise_token_auth/omniauth_callbacks#omniauth_failure
                                GET      /api/v1/customer/auth/:provider(.:format)          redirect(301)
api_v1_customer_auth_pincode GET     /api/v1/customer/auth/pincode(.:format)            api/v1/customers/registrations#verify

The problem is each time I try to access http://localhost:3000/api/v1/customer/auth/pincode
I got this error in rails stack trace is

 Started GET "/api/v1/customer/auth/pincode" for 127.0.0.1 at 2018-01-04 15:53:59 +0300
 (0.8ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY 
 "schema_migrations"."version" ASC Started GET "/omniauth/pincode?
 namespace_name=api_v1&resource_class=Customer" for 127.0.0.1 at 2018-01-04 15:53:59 +0300

  ActionController::RoutingError (No route matches [GET] "/omniauth/pincode"):

I don't understand what's going on!
Why omniauth is got the error ?
So any explanation!

@zachfeldman
Copy link
Contributor

@Mohammed-Eliass your error makes sense because there is no route for omniauth/pincode, only /api/v1/customer/auth/pincode.

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

2 participants