FOSUserBundle redirect from login page after logged in

neeraj picture neeraj · Sep 13, 2013 · Viewed 41k times · Source

I simply want that if admin user or front end user try to access login page even after logged in

/admin/login (admin user) 

OR

/login (front end user)

then they should be redirected back to their related home page like /admin or /

Answer

electronix384128 picture electronix384128 · Mar 6, 2014

The easier solution is to add these two lines to your app/config/security.yml:

always_use_default_target_path & default_target_path, e.g.:

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: /login
            check_path: /login_check
            always_use_default_target_path: false
            default_target_path:            /your/start/path/