FOSUserBundle - How to redirect already logged-in users when trying to access the login_path

前端 未结 5 2258
太阳男子
太阳男子 2020-12-19 14:02

Is it possible to perform an automatic redirect to the some route (i.e. /) for the specific route /login only for users that are AUTHENTICATED? and

5条回答
  •  情歌与酒
    2020-12-19 14:54

    I'm using the routing and security to enable this.

    #routing.yml
    index:
        path: /
        defaults: { _controller: AppBundle:Base:index }
        methods: [GET]
    
    login:
        path: /login
        defaults: { _controller: AppBundle:Security:login }
        methods: [GET]
    

    If a user is logged in, he get redirected to the dashboard. If not, he will see the login route.

    #security.yml
        access_control:
            - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/dashboard, role: ROLE_USER }
    

    Hope this helps you. :)

提交回复
热议问题