handleAuthenticationSuccess($token->getUser()); } public function handleAuthenticationSuccess(UserInterface $user, $jwt = null): Response { if (($user instanceof User) && !$user->isVerified()) { throw new AccessDeniedHttpException('You have not yet validated your email address.'); } if (null === $jwt) { $jwt = $this->jwtManager->create($user); } $jwtCookies = [ new Cookie( 'BEARER', $jwt, time() + 604800, // expiration '/', null, true, true, false, 'strict' ), ]; $response = new JWTAuthenticationSuccessResponse($jwt, [], $jwtCookies); $event = new AuthenticationSuccessEvent(['token' => $jwt], $user, $response); $this->dispatcher->dispatch($event, Events::AUTHENTICATION_SUCCESS); $responseData = $event->getData(); if ($responseData) { $response->setData($responseData); } else { $response->setStatusCode(Response::HTTP_NO_CONTENT); } return $response; } }