Feature: #100307 - PSR-14 events for user login & logout
See forge#100307
Description
Three new PSR-14 events have been added:
\TYPO3\
CMS\ Core\ Authentication\ Event\ Before User Logout Event \TYPO3\
CMS\ Core\ Authentication\ Event\ After User Logged Out Event \TYPO3\
CMS\ Core\ Authentication\ Event\ After User Logged In Event
The purpose of these events is to trigger any kind of action when a user has been successfully logged in or logged out.
TYPO3 Core itself uses After
in the TYPO3 backend
to send an email to a user, if the login was successful.
The event features the following methods:
get
: Returns theUser () \TYPO3\
derivative in questionCMS\ Core\ Authentication\ Abstract User Authentication
The PSR-14 event Before
on top has the possibility
to bypass the regular logout process by TYPO3 (removing the cookie and
the user session) by calling $event->disable
in an event listener.
The PSR-14 event After
contains the method
get
to return PSR-7 request object of the current request.
Registration of the event in your extension's Services.
:
MyVendor\MyExtension\Authentication\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/after-user-logged-in'
The corresponding event listener class for After
:
namespace MyVendor\MyExtension\Authentication\EventListener;
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
}
}
}
Impact
It is now possible to modify and adapt user functionality based on successful login or active logout.