Sha256: 4ccd28d968ccd0bcbaaed5ffa0f3e0d3bb187c864e1d6a24aa047f4e8462d027

Contents?: true

Size: 991 Bytes

Versions: 47

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true
module ShopifyApp
  module UserSessionStorage
    extend ActiveSupport::Concern
    include ::ShopifyApp::SessionStorage

    included do
      validates :shopify_domain, presence: true
    end

    class_methods do
      def store(auth_session, user)
        user = find_or_initialize_by(shopify_user_id: user[:id])
        user.shopify_token = auth_session.token
        user.shopify_domain = auth_session.domain
        user.save!
        user.id
      end

      def retrieve(id)
        user = find_by(id: id)
        construct_session(user)
      end

      def retrieve_by_shopify_user_id(user_id)
        user = find_by(shopify_user_id: user_id)
        construct_session(user)
      end

      private

      def construct_session(user)
        return unless user
        ShopifyAPI::Session.new(
          domain: user.shopify_domain,
          token: user.shopify_token,
          api_version: user.api_version,
        )
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
ruby_shopify_app-1.3.3 lib/ruby_shopify_app/session/user_session_storage.rb
ruby_shopify_app-1.3.2 lib/ruby_shopify_app/session/user_session_storage.rb
ruby_shopify_app-1.3.1 lib/ruby_shopify_app/session/user_session_storage.rb
ruby_shopify_app-1.3.0 lib/ruby_shopify_app/session/user_session_storage.rb
ruby_shopify_app-1.2.0 lib/ruby_shopify_app/session/user_session_storage.rb
ruby_shopify_app-1.1.0 lib/ruby_shopify_app/session/user_session_storage.rb
ruby_shopify_app-1.0.0 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.1.3 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.1.2 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.1.1 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.1.0 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.0.4 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.0.3 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.0.2 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.0.1 lib/shopify_app/session/user_session_storage.rb
shopify_app-18.0.0 lib/shopify_app/session/user_session_storage.rb
shopify_app-17.2.1 lib/shopify_app/session/user_session_storage.rb
shopify_app-17.2.0 lib/shopify_app/session/user_session_storage.rb
shopify_app-17.1.1 lib/shopify_app/session/user_session_storage.rb
shopify_app-17.1.0 lib/shopify_app/session/user_session_storage.rb