src/EventSubscriber/LoginSubscriber.php line 21
<?phpnamespace App\EventSubscriber;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;use Symfony\Component\Security\Http\Event\LoginSuccessEvent;class LoginSubscriber implements EventSubscriberInterface{public function __construct(private UrlGeneratorInterface $urlGenerator) {}public static function getSubscribedEvents(): array{return [LoginSuccessEvent::class => 'onLoginSuccess',];}public function onLoginSuccess(LoginSuccessEvent $event): void{$user = $event->getUser();$response = null;if(in_array('ROLE_ADMIN',$user->getRoles())){$response = new RedirectResponse($this->urlGenerator->generate('app_pos_home'),RedirectResponse::HTTP_SEE_OTHER);}elseif (in_array('ROLE_SALES_MANAGER',$user->getRoles())){$response = new RedirectResponse($this->urlGenerator->generate('app_pos_home'),RedirectResponse::HTTP_SEE_OTHER);}else{$response = new RedirectResponse($this->urlGenerator->generate('app_product_index'),RedirectResponse::HTTP_SEE_OTHER);}$event->setResponse($response);}}