G
G
gitdev2021-05-22 05:13:12
symfony
gitdev, 2021-05-22 05:13:12

What is the best way to implement a redirect if the user is authorized in Symfony?

/**
     * @param AuthenticationUtils $authenticationUtils
     * @Route("/login", name="app_login")
     * @return Response
     */
    public function login(AuthenticationUtils $authenticationUtils): Response
    {
        //Хотел бы убрать эту часть
        if($user = $this->getUser()) {
            return $this->redirectToRoute('dashboard');
        }


        return $this->render('security/login.html.twig', ['last_username' => $authenticationUtils->getLastUsername(), 'error' => $authenticationUtils->getLastAuthenticationError()]);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Derepko, 2021-05-23
@uDenX

for example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question