Do you want to know how to Drupal?

Let's Drupal

How to detect the very first login of the user in Drupal 9?

For this we need implement user_login hook and then we check the last access field.

use Drupal\user\Entity\User;

/**
 * Implements hook_user_login().
 */
function mymodule_user_login(User $user) {
  if (empty($user->getLastAccessedTime())) {
    // Do something here.
  }
}