Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1469,16 +1469,15 @@ this as the locale for the given user. To accomplish this, you can hook into
the login process and update the user's session with this locale value before
they are redirected to their first page.

To do this, you need an event subscriber on the ``security.interactive_login``
To do this, you need an event subscriber on the ``LoginSuccessEvent::class``
event::

// src/EventSubscriber/UserLocaleSubscriber.php
namespace App\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;

/**
* Stores the locale of the user in the session after the
Expand All @@ -1491,9 +1490,9 @@ event::
) {
}

public function onInteractiveLogin(InteractiveLoginEvent $event): void
public function onLoginSuccess(LoginSuccessEvent $event): void
{
$user = $event->getAuthenticationToken()->getUser();
$user = $event->getUser();

if (null !== $user->getLocale()) {
$this->requestStack->getSession()->set('_locale', $user->getLocale());
Expand All @@ -1503,7 +1502,7 @@ event::
public static function getSubscribedEvents(): array
{
return [
SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
LoginSuccessEvent::class => 'onLoginSuccess',
];
}
}
Expand Down