Shopify_app: Using nested route throws routing exception on install

Created on 19 Jun 2018  路  11Comments  路  Source: Shopify/shopify_app

I am using Rails 5.2.0, shopify_app gem 8.2.6 a shopify_api gem 4.11.0. I created bare shopify application. Then I added configuration for nested route as outlined in Nested Route section of Mounting the Engine.

When I start server and visit "localhost:3000/nested" I am redirected to login page at "localhost:3000/nested/login". After I enter development store name and hit install, I am redirected to "localhost:3000/nestedauth/shopify" which throws "No route matches [GET] "/nestedauth/shopify"" and instalation stops.

shopify-nested-route-exception

My routes.rb look like this

Rails.application.routes.draw do
  scope '/nested' do
    root :to => 'home#index'
  end
  mount ShopifyApp::Engine, at: '/nested'
end

My shopify_app.rb

ShopifyApp.configure do |config|
  config.root_url = '/nested'
  config.application_name = "My Shopify App"
  config.api_key = ...rest as generated by generator

My omniauth.rb

  Rails.application.config.middleware.use OmniAuth::Builder do
    provider :shopify,
            callback_path: '/nested/auth/shopify/callback',
             ShopifyApp.configuration.api_key ...rest as generated by generator
auth bug

Most helpful comment

I have the same issue on 8.6.0 version...

I think the issue may be caused by authenticate_in_context method of ShopifyApp::SessionsController:

def authenticate_in_context
     redirect_to "#{main_app.root_path}auth/shopify"
end

It takes root_path of the app without taking nesting into consideration...

I'm trying to do a local patch like this:

ShopifyApp::SessionsController.class_eval do
  def authenticate_in_context
    redirect_to "#{ShopifyApp.configuration.root_url}/auth/shopify"
  end
end

This fixes the url, but still there is no route for /app/auth/shopify...

@nwtn @Shine18

All 11 comments

I'm experiencing the same problem, any updates on this?

Any update on this?

Are you experiencing the behaviour with 8.4.0? The logic has changed considerably from 8.2.6 and may be resolved at this point.

I added a route '/shopify' in my routes files. and pointed it to the index of app's home controller. That's how i fixed it.

I have the same issue on 8.6.0 version...

I think the issue may be caused by authenticate_in_context method of ShopifyApp::SessionsController:

def authenticate_in_context
     redirect_to "#{main_app.root_path}auth/shopify"
end

It takes root_path of the app without taking nesting into consideration...

I'm trying to do a local patch like this:

ShopifyApp::SessionsController.class_eval do
  def authenticate_in_context
    redirect_to "#{ShopifyApp.configuration.root_url}/auth/shopify"
  end
end

This fixes the url, but still there is no route for /app/auth/shopify...

@nwtn @Shine18

This is still an issue in the current master branch. It seems to be exactly as described above.

@manuca @andreas-sotnik-2k19 I've tried to replicate this issue with a recent version of the gem (v12.0.4) and am unable to do so. What are the steps to replicate, or if you've tried it with a recent version, does it still occur?

@andreas-sotnik-2k19 I think your local patch also should help me to fix my issue.
But it looks a stupid question, in which file have you added that code?

ShopifyApp::SessionsController.class_eval do
  def authenticate_in_context
    redirect_to "#{ShopifyApp.configuration.root_url}/auth/shopify"
  end
end

@codemicky Sorry, I don't really remember where to put it... I guess application.rb may be the place.
I just migrated all of my projects to Rails 6.x (with the latest version of shopify_app gem) and everything works just fine without this code.

It seems my issue was related to Devise + omniauthable setting, not a problem with nesting routes itself. I can't confirm this 100% at this moment but I'm pretty sure that was the problem back then. I leave this as a lead in case someone wants to explore this possibility, also this article is related and proved usesful
https://www.botreetechnologies.com/blog/how-to-fix-no-route-matches-get-auth-shopify-after-introducing-devise-with-omniauth/

@manuca Good to hear you have it working, and thanks for sharing the solution.

As this ticket was originally created for a much older version of the gem (from 2018), I think it's best to close this, and for anyone who runs into similar problems to open a new ticket.

Was this page helpful?
0 / 5 - 0 ratings