You can use customer_login event observer to get customer group after login and then logout the customer in observer
app/code/Vendor/Module/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="customer_login">
<observer name="customer_login_observer" instance="Vendor\Module\Observer\CustomerLogin" />
</event>
</config>
app/code/Vendor/Module/Observer/CustomerLogin.php
<?php
namespace Vendor\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
class CustomerLogin implements ObserverInterface
{
/**
* @var \Magento\Framework\App\ResponseFactory
*/
private $responseFactory;
/**
* @var \Magento\Framework\UrlInterface
*/
private $url;
private $customerSession;
private $messageManager;
public function __construct(
\Magento\Framework\App\ResponseFactory $responseFactory,
\Magento\Framework\UrlInterface $url,
\Magento\Customer\Model\Session $customerSession,
\Magento\Framework\Message\ManagerInterface $messageManager
) {
$this->responseFactory = $responseFactory;
$this->url = $url;
$this->customerSession= $customerSession;
$this->messageManager = $messageManager;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$customerGroup = $customer->getGroupId();
if($customerGroup=="locked"){
$this->customerSession->logout();
$this->messageManager->addErrorMessage(__('You are Locked'));
$redirectionUrl = $this->url->getUrl('set-your-redirect-url');
$this->responseFactory->create()->setRedirect($redirectionUrl)->sendResponse();
return $this;
}
}
}