Sha256: f4eac56cd553d39d5a205996593b3205d03eb60346df357cfd1644ed5c3f5be1

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module ShopifyApp
  module Auth
    class PostAuthenticateTasks
      class << self
        def perform(session)
          ShopifyApp::Logger.debug("Performing post authenticate tasks")
          # Ensure we use the shop session to install webhooks
          session_for_shop = session.online? ? shop_session(session) : session

          install_webhooks(session_for_shop)

          perform_after_authenticate_job(session)
        end

        private

        def shop_session(session)
          ShopifyApp::SessionRepository.retrieve_shop_session_by_shopify_domain(session.shop)
        end

        def install_webhooks(session)
          ShopifyApp::Logger.debug("PostAuthenticateTasks: Installing webhooks")
          return unless ShopifyApp.configuration.has_webhooks?

          WebhooksManager.queue(session.shop, session.access_token)
        end

        def perform_after_authenticate_job(session)
          ShopifyApp::Logger.debug("PostAuthenticateTasks: Performing after_authenticate_job")
          config = ShopifyApp.configuration.after_authenticate_job

          return unless config && config[:job].present?

          job = config[:job]
          job = job.constantize if job.is_a?(String)

          if config[:inline] == true
            job.perform_now(shop_domain: session.shop)
          else
            job.perform_later(shop_domain: session.shop)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shopify_app-22.5.1 lib/shopify_app/auth/post_authenticate_tasks.rb
shopify_app-22.5.0 lib/shopify_app/auth/post_authenticate_tasks.rb
shopify_app-22.4.0 lib/shopify_app/auth/post_authenticate_tasks.rb
shopify_app-22.3.1 lib/shopify_app/auth/post_authenticate_tasks.rb
shopify_app-22.3.0 lib/shopify_app/auth/post_authenticate_tasks.rb
shopify_app-22.2.1 lib/shopify_app/auth/post_authenticate_tasks.rb
shopify_app-22.2.0 lib/shopify_app/auth/post_authenticate_tasks.rb
shopify_app-22.1.0 lib/shopify_app/auth/post_authenticate_tasks.rb