Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Symfony3 Update Users data and Invalidate current sessions

As I understand, When the user logs in successfully Symfony will keep a copy of the User document/entity either in the session.handler.native_file or a db provider, whichever is configured. On future requests this information is retrieved with the session id kept in the cookie.

My problem is whenever a user updates its password or username (which is their e-mail), previously opened sessions on different computers or browsers don't expire or as set as invalid.

The EquatableInterface is suppose to check against this but its not really working for me. As I added the following stub to the User class:

#User.php
public function isEqualTo(UserInterface $user)
{
    return false;
}

Followed by a refresh on the browser nothing changed. My session was still valid and checking the User fetch with a dump($this->getUser()) gave me the currently updated User and not the one was stored at the beginning of the session.

I tried using:

#security.yml
security:
    always_authenticate_before_granting: true

To if it would do anything, but it really didn't worked.

Using the Symfony Profiler, I see that a User is been fetch from the db every time I do a request and I wonder if it is at this point the the UserProviderInterface just updated the user in the security.token_storage instead of first checking against changes to end session if necessary.

To make sure this was happening I tested this controller on two different browsers:

#SomeController.php
public function indexAction()
{
    $encoder = $this->get('security.password_encoder');
    $user = $this->getUser();

    $flag = $encoder->isPasswordValid($user, 'MY_NEW_PASSWORD');

    dump($flag);

    return [];
}

I logged in to my application on both browsers, then logout on browser A. I changed the User password to 'MY_NEW_PASSWORD' and just refresh browser B. The dump was true for the new password.

If this is the case I wonder: - Is there anyway to make a check against the db before granting authorization when the User is been fetch from the security.token_storage? (It would be a service that is runs on the fetch event I guess.)

or maybe I'm over complicating stuff and there is a super simple solution that I just haven't figured out =|

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!