Skip to content

Commit

Permalink
Merge pull request #1877 from Shopify/fix-spin-install-link
Browse files Browse the repository at this point in the history
Fix unified admin install path for spin
  • Loading branch information
zzooeeyy committed Jul 8, 2024
2 parents c625c3b + f9d6fdd commit 9ca8365
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Unreleased
- Remove old translation keys for `enable_cookies_*`, `top_level_interaction_*` and `request_storage_access_*` [#1865](https://github.com/Shopify/shopify_app/pull/1865)
- Add invalid id token handling for `current_shopify_domain` method [#1868](https://github.com/Shopify/shopify_app/pull/1868)
- Keep original path and params when redirecting deep links to embed [#1869](https://github.com/Shopify/shopify_app/pull/1869)
- Fix managed install path for SPIN environments [#1877](https://github.com/Shopify/shopify_app/pull/1877)

22.2.1 (May 6,2024)
----------
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/shopify_app/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def authenticate

def start_install
shop_name = sanitized_shop_name.split(".").first
install_path = "https://admin.shopify.com/store/#{shop_name}/oauth/install?client_id=#{ShopifyApp.configuration.api_key}"
unified_admin_path = ShopifyApp::Utils.unified_admin_path(shop_name)
install_path = "#{unified_admin_path}/oauth/install?client_id=#{ShopifyApp.configuration.api_key}"
redirect_to(install_path, allow_other_host: true)
end

Expand Down
9 changes: 9 additions & 0 deletions lib/shopify_app/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def shop_login_url(shop:, host:, return_to:)
url.to_s
end

def unified_admin_path(shop)
spin_env = ENV.fetch("SPIN_FQDN", nil)
if spin_env
"https://admin.web.#{spin_env}/store/#{shop}"
else
"https://admin.shopify.com/store/#{shop}"
end
end

private

def myshopify_domain
Expand Down
12 changes: 12 additions & 0 deletions test/shopify_app/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ class UtilsTest < ActiveSupport::TestCase
assert_nil ShopifyApp::Utils.sanitize_shop_domain(bad_url)
end
end

test "#unified_admin_path returns the path to shop" do
expected = "https://admin.shopify.com/store/my-shop"
assert_equal expected, ShopifyApp::Utils.unified_admin_path("my-shop")
end

test "#unified_admin_path returns the path to shop with spin env" do
ENV["SPIN_FQDN"] = "my.spin.dev"
expected = "https://admin.web.my.spin.dev/store/my-shop"
assert_equal expected, ShopifyApp::Utils.unified_admin_path("my-shop")
ENV["SPIN_FQDN"] = nil
end
end

0 comments on commit 9ca8365

Please sign in to comment.