AfterUserLoggedInEvent
New in version 12.3
The event replaces the deprecated hook
$GLOBALS
.
The purpose of the PSR-14 event
\TYPO3\
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 (GitHub).
Example
Registration of the event listener in the extension's Services.
:
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:
<?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\
(where
necessary) like in the example above.