Do you want to know how to Drupal?

Let's Drupal

How to redirect a user after login in Drupal 9?

Let's imagine we want to send a user to custom route after login in our example to user edit form. How do we do it ?

We need to implement user_login hook

use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\user\Entity\User;

/**
 * Implements hook_user_login().
 */
function mymodule_user_login(User $user) {
    $url = Url::fromRoute('entity.user.edit_form', [
       'user' => $user->id(),
    ]);
    $redirect = new RedirectResponse($url->toString());
    $redirect->send();
}