Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh Auth user data after update

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?

like image 808
Daniel Faria Avatar asked Aug 12 '26 11:08

Daniel Faria


1 Answers

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()

like image 150
ndm Avatar answered Aug 15 '26 00:08

ndm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!