Refresh User Data in Joomla

I was busy with a custom component in Joomla, and it stored it’s own user_details based off of the main users table, but if the details were changed then I needed the system to update the session to reflect the changes.

This is what I did:

$user = JFactory::getUser();
$session = JFactory::getSession();
$session->set("user", new JUser($user->id));
$user = JFactory::getUser();