Module: ShopifyApp::Utils

Defined in:
lib/shopify_app/utils.rb

Constant Summary collapse

TRUSTED_SHOPIFY_DOMAINS =
[
  "shopify.com",
  "myshopify.io",
  "myshopify.com",
  "spin.dev",
].freeze

Class Method Summary collapse

Class Method Details

.sanitize_shop_domain(shop_domain) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shopify_app/utils.rb', line 13

def sanitize_shop_domain(shop_domain)
  uri = uri_from_shop_domain(shop_domain)
  return nil if uri.nil?

  trusted_domains.each do |trusted_domain|
    no_shop_name_in_subdomain = uri.host == trusted_domain
    from_trusted_domain = trusted_domain == uri.domain

    return myshopify_domain_from_unified_admin(uri) if unified_admin?(uri) && from_trusted_domain
    return nil if no_shop_name_in_subdomain || uri.host&.empty?
    return uri.host if from_trusted_domain
  end
  nil
end

.shop_login_url(shop:, host:, return_to:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shopify_app/utils.rb', line 28

def (shop:, host:, return_to:)
  return ShopifyApp.configuration. unless shop

  url = URI(ShopifyApp.configuration.)

  url.query = URI.encode_www_form(
    shop: shop,
    host: host,
    return_to: return_to,
  )

  url.to_s
end