UNPKG

@shopgate/pwa-webcheckout-shopify

Version:

Webcheckout Shopify library for the Shopgate Connect PWA.

8 lines 1.49 kB
import{mutable}from'@shopgate/pwa-common/helpers/redux';import HttpRequest from'@shopgate/pwa-core/classes/HttpRequest';import requestShopifyLogin from"../action-creators/requestShopifyLogin";import errorShopifyLogin from"../action-creators/errorShopifyLogin";import successShopifyLogin from"../action-creators/successShopifyLogin";import{isShopify,getShopifyUrl}from"../selectors";/** * Login the current user. * @param {string} user The login user name. * @param {string} password The login password. * @return {Function} A redux thunk. */var webCheckoutLogin=function webCheckoutLogin(user,password){return function(dispatch){if(!isShopify()){// The success is dispatched here to take care that the streams work as expected dispatch(successShopifyLogin());return;}dispatch(requestShopifyLogin());new HttpRequest("".concat(getShopifyUrl(),"/account/login")).setMethod('POST').setTimeout(20000).setPayload({// eslint-disable-next-line camelcase form_type:'customer_login',customer:{email:user,password:password}}).dispatch().then(function(response){var _response$headers=response.headers,_response$headers2=_response$headers===void 0?{}:_response$headers,location=_response$headers2.location,statusCode=response.statusCode;if(statusCode===302&&location&&location.endsWith('/account')){dispatch(successShopifyLogin());}else{dispatch(errorShopifyLogin());}})["catch"](function(){dispatch(errorShopifyLogin());});};};/** @mixes {MutableFunction} */export default mutable(webCheckoutLogin);