@@ -1469,16 +1469,15 @@ this as the locale for the given user. To accomplish this, you can hook into
1469
1469
the login process and update the user's session with this locale value before
1470
1470
they are redirected to their first page.
1471
1471
1472
- To do this, you need an event subscriber on the ``security.interactive_login ``
1472
+ To do this, you need an event subscriber on the ``LoginSuccessEvent::class ``
1473
1473
event::
1474
1474
1475
1475
// src/EventSubscriber/UserLocaleSubscriber.php
1476
1476
namespace App\EventSubscriber;
1477
1477
1478
1478
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1479
1479
use Symfony\Component\HttpFoundation\RequestStack;
1480
- use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
1481
- use Symfony\Component\Security\Http\SecurityEvents;
1480
+ use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
1482
1481
1483
1482
/**
1484
1483
* Stores the locale of the user in the session after the
@@ -1491,9 +1490,9 @@ event::
1491
1490
) {
1492
1491
}
1493
1492
1494
- public function onInteractiveLogin(InteractiveLoginEvent $event): void
1493
+ public function onLoginSuccess(LoginSuccessEvent $event): void
1495
1494
{
1496
- $user = $event->getAuthenticationToken()-> getUser();
1495
+ $user = $event->getUser();
1497
1496
1498
1497
if (null !== $user->getLocale()) {
1499
1498
$this->requestStack->getSession()->set('_locale', $user->getLocale());
@@ -1503,7 +1502,7 @@ event::
1503
1502
public static function getSubscribedEvents(): array
1504
1503
{
1505
1504
return [
1506
- SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin ',
1505
+ LoginSuccessEvent::class => 'onLoginSuccess ',
1507
1506
];
1508
1507
}
1509
1508
}
0 commit comments