trenpixster / addict

User management lib for Phoenix Framework
MIT License
645 stars 99 forks source link

`Addict.Helpers.current_user` can grow stale #112

Open eteeselink opened 8 years ago

eteeselink commented 8 years ago

Hey there!

I'm not sure if this is a bug, a feature request, or simply a bad idea but I've noticed that the user object is stored in the Phoenix session once on login and then never updated.

I solved it for my particular case by making a refresh_user helper and calling it in the appropriate controller functions:

  defp refresh_user(conn) do
    stale_user = Addict.Helper.current_user conn
    {:ok, user} = Addict.Interactors.GetUserById.call stale_user.id
    {:ok, conn} = Addict.Interactors.CreateSession.call conn, user
    conn
  end

I reused some nice helper functions from Addict, not sure the Interactors were supposed to be used this way. Is this an approach that you'd support? Would it be useful to add this to Addict.Helper maybe? If so, I'll happily make a PR.

Or did I totally not understand something and shouldn't I be wanting to refresh the user hash in the session?