I'm displaying the name of the loggedin user in the header with $this->Auth->user('name').
The issue is, when I update the name of the user how can I refresh this value at $this->Auth->user() because after I just updated the old name still?
Unless you are using stateless authentication, the data is stored and retrieved from the session, so you just need to update it there.
For example
$this->Auth->session->write($this->Auth->sessionKey . '.name', $newName);
Or maybe set the complete modified user data in case applicable (note that this will renew the session)
$this->Auth->setUser($updatedUserData);
See also API > Controller > Component > AuthComponent::_setUser()
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