Symfony 5 login page redirecting to login page after submit, Session keeps on increasing on session table

Symfony 5 login not showing any errors on login page with invalid credential and redirected to login page if it’s correct credential.

public function getUser($credentials, UserProviderInterface $userProvider)
    $token = new CsrfToken('authenticate', $credentials['csrf_token']);
    if (!$this->csrfTokenManager->isTokenValid($token)) {
        throw new InvalidCsrfTokenException();

    $user = $this->entityManager->getRepository(User::class)->findOneBy(['username' => $credentials['username']]);

    if (!$user) {
        // fail authentication with a custom error
        throw new CustomUserMessageAuthenticationException('Username could not be found.');

    return $user;

public function checkCredentials($credentials, UserInterface $user)
    return $this->passwordEncoder->isPasswordValid($user, $credentials['password']);

public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey)
    if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) {
        return new RedirectResponse($targetPath);

    return new RedirectResponse($this->urlGenerator->generate('reports'));

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *