UNPKG

@shopgate/pwa-webcheckout-shopify

Version:

Webcheckout Shopify library for the Shopgate Connect PWA.

6 lines 1.4 kB
import{mutable}from'@shopgate/pwa-common/helpers/redux';import HttpRequest from'@shopgate/pwa-core/classes/HttpRequest';import requestShopifyLogout from"../action-creators/requestShopifyLogout";import errorShopifyLogout from"../action-creators/errorShopifyLogout";import successShopifyLogout from"../action-creators/successShopifyLogout";import{getLogoutUrl,getLogoutSuccessUrl}from"../selectors";/** * Log out the current user. * @return {Function} A redux thunk. */var webCheckoutLogout=function webCheckoutLogout(){return function(dispatch){var logoutUrl=getLogoutUrl();if(!logoutUrl){// When no logout url is available it doesn't make sense to do the request return;}dispatch(requestShopifyLogout());new HttpRequest(logoutUrl).dispatch().then(function(response){var _response$headers=response.headers,_response$headers2=_response$headers===void 0?{}:_response$headers,location=_response$headers2.location,statusCode=response.statusCode;var logoutSuccessUrl=getLogoutSuccessUrl();// When a success url is available it needs to be considered at the response evaluation var urlCheckValid=!logoutSuccessUrl||location&&location.startsWith(logoutSuccessUrl);if(statusCode===302&&urlCheckValid){dispatch(successShopifyLogout());}else{dispatch(errorShopifyLogout());}})["catch"](function(){dispatch(errorShopifyLogout());});};};/** @mixes {MutableFunction} */export default mutable(webCheckoutLogout);