In my view part, I have shown the current logged in user details with the phoenix inbuilt variable which stores current logged in user details. I have used code like as shown below
<%= @current_user.email %> or <%= @current_user.name %> or <%= @current_user.profile_image %>
I have created a page where user can update his name or email or profile picture. But after update user details
if user moves to another page where I have called the
<%= @current_user.name %>
The above code showing the old data not the updated data, I have checked my database and the values are going into the DB correctly so why the current user not showing the updated details and how can I fix this issue.
I have tried to pull the user details by running the ECTO.query select and getting correct record but what should I do assing the updates made by user to the phoenx inbuilt varialble current_user.
The user struct fetched can be out of sync with the database if the row in the database is updated by actions outside Pow. In this case it’s recommended to add a plug that reloads the user struct and reassigns it to the connection.
Normally you’ll want to do a redirect after modifications to the database, so hitting e.g. F5 in browsers doesn’t reissue the modification request again. This has the sideeffect, that any things you query as part of your plug pipeline will also be up to date.
This won’t be sufficient here because @current_user is assigned from the cache by Pow plug. Unless user is updated by Pow methods, the cache won’t be updated. Then we have to tell Pow to update the cache.