Sha256: 73b172f152c4c5bd84a1dabb2353e85ba7439206dd95bdbb7690a69410a42507

Contents?: true

Size: 673 Bytes

Versions: 2

Compression:

Stored size: 673 Bytes

Contents

module ShopifyApp::LoginProtection
  extend ActiveSupport::Concern
  
  included do
    rescue_from ActiveResource::UnauthorizedAccess, with: :close_session
  end
  
  def shopify_session
    if session[:shopify]
      begin
        # session[:shopify] set in LoginController#finalize
        ShopifyAPI::Base.activate_session(session[:shopify])
        yield
      ensure 
        ShopifyAPI::Base.clear_session
      end
    else
      session[:return_to] = request.fullpath
      redirect_to login_path
    end
  end
  
  def shop_session
    session[:shopify]
  end
  
  protected
  
  def close_session
    session[:shopify] = nil
    redirect_to login_path
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify_app-4.1.0 lib/shopify_app/login_protection.rb
shopify_app-4.0.1 lib/shopify_app/login_protection.rb