Change Engine Routes For Shopify_app Gem
I am using shopify_app gem with rails 5. I want the shopify_app to work from a nested route. For eg: /shopify_app/login or '/shopify_app/auth/shopify/callback'.
I tried the solution given in gem documentation and put these lines in my routes.rb file:
mount ShopifyApp::Engine, at: 'shopify_app' get '/shopify_app' => 'settings#index'
But it didn't work this way. So I googled around and found a solution to make it work by doing some changes in an omniauth initializer.
Rails.application.config.middleware.use OmniAuth::Builder do provider :shopify, ShopifyApp.configuration.api_key, ShopifyApp.configuration.secret, scope: ShopifyApp.configuration.scope, callback_path: '/shopify_app/auth/shopify/callback' end
Here are the app settings:
Embedded App SDK: enabled
App Url: https://salebait.com/settings
Whitelisted Redirection Url: https://salebait.com/shopify_app/auth/shopify/callback
Now the problem is when I install my app for the first time it redirects to my website's homepage (https://salebait.com) after installation but it should open https://salebait.com/settings page in store admin instead. And if I close the browser or logout from the store and come back again to the app it goes to https://salebait.com/login which is not a valid page since all app routes are wrapped inside /shopify_app/ so the login URL for the app should be https://salebait.com/shopify_app/login. Then I have to manually hit the app's login URL to make it work.
Please suggest some solution make my app routes work smoothly.
If anyone else is looking for the solution, here it is: I was mounting the shopify_app engine under "/shopify_app" namespace. but it is the gem's default namespace so it won't override default routes.
So I changed the shopify_app namespace to "/app" and it worked smoothly.
mount ShopifyApp::Engine, at: 'app' get '/app' => 'settings#index'
Also changed the path in Omniauth builder and app settings.
Rails.application.config.middleware.use OmniAuth::Builder do provider :shopify, ShopifyApp.configuration.api_key, ShopifyApp.configuration.secret, scope: ShopifyApp.configuration.scope, callback_path: '/app/auth/shopify/callback' end
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How to map API params to model
- → Consuming webhooks shopify-api
- → How to add ScriptTag on shopify_api gem?