LogoutConfirmedEvent

The PSR-14 event \TYPO3\CMS\FrontendLogin\Event\LogoutConfirmedEvent is triggered when a logout was successful.

Example: Delete stored private key from disk on logout

Upon logout a private key the user uploaded for decryption of private information should be deleted at once. There is only a logout event if the user actively clicks the logout button, so if the user would just close the browser window there would be no LogoutConfirmedEvent. For this case we need a second line of defense like a scheduler task (out of scope of this example).

The currently logged-in user derived from the \TYPO3\CMS\Core\Context\Context is now an anonymous user that is not logged in. The information on which user just logged out cannot be determined from the context or the methods from the event. We therefore need different logic to determine the user who just logged out. This logic is not part of the example below.

Register the event listener in the Services.yaml:

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

  MyVendor\MyExtension\EventListener\DeletePrivateKeyOnLogout:
    tags:
      - name: event.listener
        identifier: 'my-extension/delete-private-key-on-logout'
Copied!

Read how to configure dependency injection in extensions.

EXT:my_extension/Classes/EventListeners/DeletePrivateKeyOnLogout.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

use MyVendor\MyExtension\KeyPairHandling\KeyFileService;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\FrontendLogin\Event\LogoutConfirmedEvent;

final class LogoutEventListener
{
    public function __construct(
        private readonly KeyFileService $keyFileService,
        private readonly Context $context,
    ) {}

    public function __invoke(LogoutConfirmedEvent $event): void
    {
        $userAspect = $this->context->getAspect('frontend.user');
        assert($userAspect instanceof UserAspect);
        if ($this->keyFileService->deletePrivateKey($userAspect)) {
            $event->getController()->addFlashMessage('Your private key has been deleted. ', '', ContextualFeedbackSeverity::NOTICE);
        } else {
            $event->getController()->addFlashMessage('Deletion of your private key failed. It will be deleted automatically within 15 minutes by a scheduler task. ', '', ContextualFeedbackSeverity::WARNING);
        }
    }
}
Copied!

API

class LogoutConfirmedEvent
Fully qualified name
\TYPO3\CMS\FrontendLogin\Event\LogoutConfirmedEvent

A notification when a log out has successfully arrived at the plugin, via the view and the controller, multiple information can be overridden in Event Listeners.

getController ( )
Returns
TYPO3CMSFrontendLoginControllerLoginController
getView ( )
Returns
TYPO3FluidFluidViewViewInterface