@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
6 lines • 1.14 kB
JavaScript
import{PipelineRequest}from'@shopgate/pwa-core';import{requestLogout,successLogout,errorLogout}from"../../action-creators/user";import{SHOPGATE_USER_LOGOUT_USER}from"../../constants/Pipelines";import{mutable}from"../../helpers/redux";/**
* Logout the current user.
* @param {boolean} [notify=true] If set to TRUE users are notified when the logout was successful.
* @param {boolean} [autoLogout=false] Whether the logout happened because session expired
* @return {Function} A redux thunk.
*/function logout(){var notify=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var autoLogout=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return function(dispatch){dispatch(requestLogout());var request=new PipelineRequest(SHOPGATE_USER_LOGOUT_USER).setTrusted().dispatch();request.then(function(result){var success=result.success,messages=result.messages;if(success){dispatch(successLogout(notify,autoLogout));}else{dispatch(errorLogout(messages,autoLogout));}})["catch"](function(){dispatch(errorLogout(undefined,autoLogout));});return request;};}/** @mixes {MutableFunction} */export default mutable(logout);