Symfony2- Login Form appears again after logged in Symfony2- Login Form appears again after logged in symfony symfony

Symfony2- Login Form appears again after logged in


Symfony won't automatically do this because login page is always accessible as indicated in security.yml:

access_control:    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

If you don't want authenticated users to get to the login page, you need to manually redirect them away from login page. To do that, go to your Controller for login action and at the beginning of loginAction() function add this:

public function loginAction(){    if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY'))    {        // redirect authenticated users to homepage        return $this->redirect($this->generateUrl('_homepage'));    }    //other code goes here...}

This will redirect authenticated users to your homepage. Of course, replace '_homepage' to route name of a page you wish to redirect users to.


can you update question with your routes?

I think you should have default path (for example, /secure-area) that requires authentication and some other (for example, /secure-area/login) that represents your login form. So, basically, returning visitor would not visit /secure-area/login but /secure-area instead. This way it would not show login for but reload user from session...