Skip to content

Commit

Permalink
Refactor to single layer of abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ragalie committed Apr 15, 2020
1 parent 58faad0 commit 06e125d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/controllers/shopify_app/callback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@ def callback
end

def jwt_callback
if auth_hash && jwt_shopify_domain == shop_name && jwt_shopify_user_id == associated_user_id
session_store = ShopifyAPI::Session.new(
domain: shop_name,
token: token,
api_version: ShopifyApp.configuration.api_version
)

ShopifyApp::SessionRepository.store_user_session(session_store, associated_user)

if valid_jwt_auth?
create_user_session_from_jwt_callback
head(:ok)
else
head(:unauthorized)
Expand All @@ -42,6 +35,20 @@ def jwt_callback

private

def valid_jwt_auth?
auth_hash && jwt_shopify_domain == shop_name && jwt_shopify_user_id == associated_user_id
end

def create_user_session_from_jwt_callback
session = ShopifyAPI::Session.new(
domain: shop_name,
token: token,
api_version: ShopifyApp.configuration.api_version
)

ShopifyApp::SessionRepository.store_user_session(session, associated_user)
end

def login_shop
reset_session_options
set_shopify_session
Expand Down

0 comments on commit 06e125d

Please sign in to comment.