I cannot logout a user.
I ported custom user management logic over to a Symfony 4 project. It uses recipes for security
and guard
.
Here is the logout
config in my main firewall:
logout:
path: /logout
target: /
Result:
- User goes to /logout
- User is redirected to /
- is_granted("IS_AUTHENTICATED_REMEMBERED")
continues to return true
in my template (false
is expected)
Other Considerations:
- The firewall entry is getting triggered because I get errors if I remove it
- I have tried adding additional parameters to logout
to destroy the session and cookies, however that made no difference
- Logging in works fine
Any idea on how to troubleshoot this?
:: edit - added security.yaml
as requested ::
security:
encoders:
App\Entity\User: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
app_users:
entity: { class: App\Entity\User, property: email }
app_oauth:
id: app.oauth_user_provider
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
provider: app_users
anonymous: ~
oauth:
resource_owners:
google: "/login/check-google"
default_target_path: /
login_path: /
failure_path: /login
oauth_user_provider:
service: app.oauth_user_provider
remember_me:
secret: "%env(APP_SECRET)%"
lifetime: 2592000
path: /
guard:
authenticators:
- App\Security\LoginFormAuthenticator
entry_point: App\Security\LoginFormAuthenticator
logout:
path: /logout
target: /
switch_user: ~
Add these commands
In security.yaml
logout:
path: /logout
target: /
invalidate_session: true
In controller
/**
* @Route("/logout", name="logout")
*/
public function logout()
{
}
In logout button
<a class="text-muted" href="{{ path('logout') }}">logout </a>
Check the serialize
and unserialize
methods for field $this->email
in App\Entity\User
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With