How to reassign value to current_user variable after update made by user

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

<%= %> or <%= %> 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

<%= %>

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.

That is normal as stated in the readme:

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.

1 Like

That’s a “problem” of pow, or more specifically the caching it uses, though. I don’t see a mention of both in the initial post.

1 Like

Oh my bad ! I just assumed he is using Pow maybe because of his previous threads, but he didn’t mention Pow in this one.

1 Like

Yes you are correct it is related to Pow I forgot to mention it.