AfterUserLoggedInEvent

New in version 12.3: The event replaces the deprecated hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['backendUserLogin'].

The purpose of the PSR-14 event \TYPO3\CMS\Core\Authentication\Event\AfterUserLoggedInEvent is to trigger any kind of action when a backend user has been successfully logged in.

The TYPO3 Core itself uses this event in the TYPO3 backend to send an email to a user, if the user has successfully logged in. See EXT:backend/Classes/Security/EmailLoginNotification.php.

Example

Registration of the event listener in the extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  MyVendor\MyExtension\Authentication\EventListener\MyEventListener:
    tags:
      - name: event.listener
        identifier: 'my-extension/after-user-logged-in'

Read how to configure dependency injection in extensions.

An implementation of the event listener:

EXT:my_extension/Authentication/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Authentication\EventListener;

use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Authentication\Event\AfterUserLoggedInEvent;

final class MyEventListener
{
    public function __invoke(AfterUserLoggedInEvent $event): void
    {
        if (
            $event->getUser() instanceof BackendUserAuthentication
            && $event->getUser()->isAdmin()
        ) {
            // Do something like: Clear all caches after login
        }
    }
}

Note

With TYPO3 v13 the event is also dispatched when a successful frontend user login is performed. Prepare your code and check, if the user is an instance of \TYPO3\CMS\Core\Authentication\BackendUserAuthentication (where necessary) like in the example above.

API

class TYPO3\CMS\Core\Authentication\Event\AfterUserLoggedInEvent

Event fired after a user has been actively logged in (incl. possible MFA).

Currently only working in BE context, but might get opened up in FE context as well in TYPO3 v13+.

getUser()
Return type

TYPO3\CMS\Core\Authentication\AbstractUserAuthentication

getRequest()
Return type

Psr\Http\Message\ServerRequestInterface