From 06e125df32f8a8bad9727f13b51c8010c0549c6e Mon Sep 17 00:00:00 2001 From: Mike Ragalie Date: Tue, 14 Apr 2020 15:14:30 -0400 Subject: [PATCH] Refactor to single layer of abstraction --- .../shopify_app/callback_controller.rb | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/controllers/shopify_app/callback_controller.rb b/app/controllers/shopify_app/callback_controller.rb index f5f7d49f5..0eeb53313 100644 --- a/app/controllers/shopify_app/callback_controller.rb +++ b/app/controllers/shopify_app/callback_controller.rb @@ -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) @@ -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