urlGenerator = $urlGenerator; } public function authenticate(Request $request): PassportInterface { $email = $request->request->get('email', ''); $request->getSession()->set(Security::LAST_USERNAME, $email); return new Passport( new UserBadge($email), new PasswordCredentials($request->request->get('password', '')), [ new CsrfTokenBadge('authenticate', $request->get('_csrf_token')), ] ); } public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { if ($targetPath = $this->getTargetPath($request->getSession(), $firewallName)) { return new RedirectResponse($targetPath); } return new RedirectResponse($this->urlGenerator->generate('user_page')); } protected function getLoginUrl(Request $request): string { return $this->urlGenerator->generate(self::LOGIN_ROUTE); } }