Skip to main content
Version tags should be used for questions that apply to a version only, not to merely say what version a site is using.
Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126
Source Link
dibs
  • 818
  • 2
  • 12
  • 33

How can I catch a login event in a subscriber?

I've got an event that is triggered on hook_user_login in a module.

$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch('mymodule_user_login', $event);

I also have a subscriber that I think should be catching this event.

public function mymodule_user_login(GetResponseEvent $event) {...

static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = ['mymodule_user_login', 1];
    return $events;
}

The event seems to fire when I log in, however the subscriber runs on every page load afterwards.

Do I need to somehow clear the event in the subscriber?