1
1
111ilya1112019-06-24 19:48:07
symfony
111ilya111, 2019-06-24 19:48:07

Authorized user and /login. how to redirect correctly?

Sorry for the stupid and simple question.
How to make it kosher so that an authorized user cannot access the /login and /register pages.
Everywhere in the documentation I found only this:
security.yaml
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
Therefore, anyone can enter. There was an option to redirect in the authorized controller.
In general, how to do it right?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kafkiansky, 2019-06-24
@111ilya111

In 2 steps:
1. Close the "Login" and "Register" buttons if the user is authorized (i.e. the usual condition in the template for checking authorization {% if app.user %} ...)
2. And close these actions with annotations @IsGranted or do a redirect. You have only two such actions, so don't spoil the code too much.

D
Denis Derepko, 2019-06-24
@uDenX

As an option:

- { path: ^/login, allow_if: 'is_granted("IS_AUTHENTICATED_ANONYMOUSLY") && !is_granted("IS_AUTHENTICATED_FULLY")' }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question