0
votes

So here's the thing, I created a symfony 4 app with 2 roles: ROLE_USER and ROLE_Admin with 2 pages: user page and Admin page. I'm totally new to symfony and the docs aren't helping. Now I want the login screen to direct each user to his respective page. I'm using the default security.yml and It's directing to the default home page. here's my security.yaml file:

security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
    hamda:
        entity:
            class: App\Entity\User
            property: username

encoders:
    App\Entity\User: bcrypt

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        anonymous: true
        provider: hamda
        form_login:
            login_path: login
            check_path: login
            default_target_path: /home


# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
    - { path: ^/admin, roles: ROLE_ADMIN }
1
That was made for Symfony 2 and 3, would it still work ? - Hyperion
ah the third comment worked. But I hope there's more practical method. - Hyperion

1 Answers

4
votes

This would be probably the correct way to solve this in symfony 4:

https://stackoverflow.com/a/41441034/9757801

So with a custom guard it's pretty easy to realize this.