Login wih the same login_check Sonata User bundle and Sonata admin bundle
-
25-05-2021 - |
Question
I got a app who has Sonata User bundle
and Sonata Admin bundle
, but when I login with
Sonata User bundle, and after I try to go to the admin page, I have to do login again,
Some Know how to ingrate both, to just has one login
Thanks any advice!!
Solution
Well I found the solution, I put the same check_path
and login_path
in the admin firewall that take by default in the main firewall,
Here I share the code in the security.yml:
# -> custom firewall for the admin area of the URL
admin:
pattern: /(.*)
fr3d_ldap:
check_path: /login_check
form_login:
provider: fos_userbundle
login_path: /login
use_forward: false
check_path: /login_check
failure_path: null
default_target_path: /admin/
logout:
path: /logout
anonymous: true
# -> end custom configuration
# defaut login area for standard users
main:
pattern: .*
fr3d_ldap: ~
form_login:
always_use_default_target_path: true
default_target_path: /
I hope this help to someone!!
OTHER TIPS
When you are login with firewall "admin" the firewall "main" doesn't know about you, because SESSION is writting with default prefix (name of the firewall). You need to use 1 contex for different firewalls (in app/config/security.yml):
admin:
pattern: /admin(.*)
context: user
form_login:
.....
main:
pattern: ^/
context: user
form_login:
.....
context: user