Sha256: 912d3a8e572910fe44ab6f65c6b9ed13aeb96d6fd848f2a59b8c92c9bb333911

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module ShopifyApp
  module RequireKnownShop
    extend ActiveSupport::Concern
    include ShopifyApp::RedirectForEmbedded

    included do
      before_action :check_shop_domain
      before_action :check_shop_known
    end

    def current_shopify_domain
      return if params[:shop].blank?

      @shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop])
    end

    private

    def check_shop_domain
      redirect_to(ShopifyApp.configuration.login_url) unless current_shopify_domain
    end

    def check_shop_known
      @shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain)
      unless @shop
        if embedded_param?
          redirect_for_embedded
        else
          redirect_to(shop_login)
        end
      end
    end

    def shop_login
      url = URI(ShopifyApp.configuration.login_url)

      url.query = URI.encode_www_form(
        shop: params[:shop],
        host: params[:host],
        return_to: request.fullpath,
      )

      url.to_s
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shopify_app-21.2.0 app/controllers/concerns/shopify_app/require_known_shop.rb
shopify_app-21.1.1 app/controllers/concerns/shopify_app/require_known_shop.rb
shopify_app-21.1.0 app/controllers/concerns/shopify_app/require_known_shop.rb
shopify_app-21.0.0 app/controllers/concerns/shopify_app/require_known_shop.rb
shopify_app-20.2.0 app/controllers/concerns/shopify_app/require_known_shop.rb
shopify_app-20.1.1 app/controllers/concerns/shopify_app/require_known_shop.rb
shopify_app-20.1.0 app/controllers/concerns/shopify_app/require_known_shop.rb