Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect after login in Symfony 2

In Symfony 2 you can set up a target for the logout so that after logout you will be redirected to /main. However with the login you will be redirected to /. Is there a manner to setup a target for a (successful) login as well?

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern:  ^/m/login$
        security: false

    secured_area:
        pattern:    ^/m
        form_login:
            check_path: /m/login_check
            login_path: /m/login
        logout:
            path:   /m/logout
            target: /main
        anonymous: ~
like image 237
Roel Veldhuizen Avatar asked Dec 04 '11 10:12

Roel Veldhuizen


1 Answers

Yes. You can use the target_path option. Using your example above:

firewalls:
    secured_area:
        form_login:
            always_use_default_target_path: true
            default_target_path: /loggedinpage

With the above the user will always be redirected to /loggedinpage upon a successful login. Details of all the options for the security component are available in the Symfony docs (albeit slightly hidden away!)

like image 103
richsage Avatar answered Oct 22 '22 22:10

richsage