Modal does not handle errors on login I have used 'use-ajax' class to render login form in a modal.
I want to handle validation errors on same modal without closing it.
On successful login it is redirecting correctly, but when an error occurs it closes modal and redirecting to login page i.e user/login and displaying errors on that page.
I tried to use ajax callback to display error on modal itself by altering the form which is working. But, it is giving me drupal ajax error.
Here is my code : 

$form['#prefix'] = '&lt;div id="modal-form"&gt;';
$form['#suffix'] = '&lt;/div&gt;';
$form['status_messages'] = [ 
    '#type' =&gt; 'status_messages',
    '#weight' =&gt; -10,
];
//$form['actions']['submit']['#limit_validation_errors'] = array();
$form['actions']['submit']['#ajax'] = array(
    'callback' =&gt; 'setMessage',
    'wrapper' =&gt; 'modal-form',
);




function setMessage(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {

    $response = new AjaxResponse();

    if ($form_state-&gt;hasAnyErrors()) {
        $response-&gt;addCommand(new ReplaceCommand('#modal-form', $form));
    }
    else {
        $command = new CloseModalDialogCommand('#modal-form', FALSE);
        $response-&gt;addCommand($command);
    }
    return $response;

}


The above code giving me session id also but due to drupal ajax error it does not redirect on success by closing modal.
I have resolved it by commenting redirection code from hook_login and added redirection code related changes in ajax callback function itself. Here is my code.

function setMessage(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {

     $response = new AjaxResponse();
     $current= \Drupal::currentUser();
     if ($form_state-&gt;hasAnyErrors()) {
         $response-&gt;addCommand(new ReplaceCommand('#modal-form', $form));

     }
     else if (!$current-&gt;id()) {
         $response-&gt;addCommand(new ReplaceCommand('#modal-form', $form));
     }
     else {
         $command = new RedirectCommand(' ');

         return $response-&gt;addCommand($command);
     }
     return $response;
}