Im trying to extend a navbar dropdown Login form in base.html.twig SYMFONY

Im trying to extend a navbar dropdown Login form in base.html.twig so i can have the login form in the whole website but the problem is that when i submit my account it doesnt login except in one route the one that is in LoginFormAuthenticator in a var

public const LOGIN_ROUTE = 'dashboard';

so if its dashboard it will login in dashboard but when im in another page and i try to login it doesnt do anything.the code

public function supports(Request $request)
    return self::LOGIN_ROUTE === $request->attributes->get('_route')
        && $request->isMethod('POST');

public function getCredentials(Request $request)
    $credentials = [
        'email' => $request->request->get('email'),
        'password' => $request->request->get('password'),
        'csrf_token' => $request->request->get('_csrf_token'),

    return $credentials;

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(['email' => $credentials['email']]);

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

    return $user;

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

 * Used to upgrade (rehash) the user's password automatically over time.
public function getPassword($credentials): ?string
    return $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('/');
    //throw new Exception('TODO: provide a valid redirect inside '.__FILE__);

protected function getLoginUrl()
    return $this->urlGenerator->generate(self::LOGIN_ROUTE);

and my base.html.twig

<nav class="navbar navbar-fixed-top "><div class="nav-item dropdown" id="topnavbar2">
                    <button type="button" class="btn dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <i class="far fa-user" id="colorblack"></i>
                        <div class="dropdown-menu">   
                            {{ render(controller('AppControllerSecurityController:minilogin')) }}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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