You can do it by plugin way, create simple module, app/code/Rbj/Test/etc/frontend/di.xml <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Controller\Ajax\Login">
<plugin name="customer-login-after"
type="Rbj\Test\Plugin\Afterlogin"/>
</type>
</config> Create plugin file, app/code/Rbj/Test/Plugin/Afterlogin.php <?php
namespace Rbj\Test\Plugin;
class Afterlogin
{
public function __construct(
\Magento\Framework\UrlInterface $url,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
$this->url = $url;
$this->resultJsonFactory = $resultJsonFactory;
}
public function afterExecute(\Magento\Customer\Controller\Ajax\Login $subject)
{
$response['redirectUrl'] = $this->url->getUrl('customer/account/index');
$resultJson = $this->resultJsonFactory->create();
return $resultJson->setData($response);
}
} Now override core magento_customer js file, vendor/magento/module-customer/view/frontend/web/js/action/login.js to your module and keep below code, /*global define*/
define(
[
'jquery',
'mage/storage',
'Magento_Ui/js/model/messageList',
'Magento_Customer/js/customer-data'
],
function($, storage, globalMessageList, customerData) {
'use strict';
var callbacks = [],
action = function(loginData, redirectUrl, isGlobal, messageContainer) {
messageContainer = messageContainer || globalMessageList;
return storage.post(
'customer/ajax/login',
JSON.stringify(loginData),
isGlobal
).done(function (response) {
if (response.errors) {
messageContainer.addErrorMessage(response);
callbacks.forEach(function(callback) {
callback(loginData);
});
} else {
callbacks.forEach(function(callback) {
callback(loginData);
});
customerData.invalidate(['customer']);
if (response.redirectUrl) {
window.location.href = response.redirectUrl;
} else if (redirectUrl) {
window.location.href = redirectUrl;
} else {
location.reload();
}
}
}).fail(function () {
messageContainer.addErrorMessage({'message': 'Could not authenticate. Please try again later'});
callbacks.forEach(function(callback) {
callback(loginData);
});
});
};
action.registerLoginCallback = function(callback) {
callbacks.push(callback);
};
return action;
}
); if issue soled, Click Kudos/Accept as solutions.
... View more