Just in case anyone is looking for answer to this question:
There is event observer which looks for previous url and login actions. Here is the code:
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;
class CustomerAuthenticated implements ObserverInterface
{
/**
* Core store config
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* Uri Validator
*
* @var \Zend\Validator\Uri
*/
protected $uri;
/**
* @var \Magento\Framework\App\ResponseFactory
*/
protected $responseFactory;
/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Zend\Validator\Uri $uri
* @param \Magento\Framework\App\ResponseFactory $responseFactory
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Zend\Validator\Uri $uri,
\Magento\Framework\App\ResponseFactory $responseFactory,
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magento\Framework\App\Response\RedirectInterface $redirect,
\Magento\Framework\UrlInterface $urlInterface
) {
$this->scopeConfig = $scopeConfig;
$this->uri = $uri;
$this->responseFactory = $responseFactory;
$this->_objectManager = $objectManager;
$this->redirect = $redirect;
$this->_urlInterface = $urlInterface;
}
/**
* Handler for 'customer_login' event.
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$redirectDashboard = $this->scopeConfig->isSetFlag(
'customer/startup/redirect_dashboard',
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES
);
$redirectUrl = $this->redirect->getRedirectUrl();
// if the Redirect Customer to Account Dashboard after Logging in set to "No"
if (!$redirectDashboard) {
$account_url = $this->_urlInterface->getUrl('customer/account');
$cart_url = $this->_urlInterface->getUrl('checkout/cart');
if (strpos($redirectUrl, 'abandoned') !== false) {
$redirect_url = $cart_url;
}else {
$redirect_url = $account_url;
}
$resultRedirect = $this->responseFactory->create();
$resultRedirect->setRedirect($redirect_url)->sendResponse('200');
exit();
}
}
}`