POW & LiveView - best way to implement `assigns.current_user`?

Hi everyone,

What is the standard way to retrieve “current_user” in Liveview using POW?

I’m starting a project from scratch with LiveView and POW, and despite several topics discussing the problem, I can’t find any documented solution or tutorial. Even less on recent versions.

My questions:

  1. To retrieve the current_user with POW, should I use Pow.Plug.current_user() or Pow.Store.CredentialsCache.get()? What are the differences, and what is the modern method?
  2. From what I understand, as these two functions require a conn, I have to create a plug with a put_session() function to add the current user ID → Is there a recommended way to do this? Where should the plug be?
  3. Once the current user ID is in the session, do I have to assign_new(socket, :current_user, Users.get_user(session["current_user_id"]) in the mount() of each LiveView? Or there’s a more practical way to do it?

A guide on the subject, particularly in the docs, would be welcome.

Thanks for any help :slight_smile:

Found this gist → https://dev.to/oliverandrich/how-to-connect-pow-and-live-view-in-your-phoenix-project-1ga1

Really helpful, and answered my questions. But I still think we could have a guide about it in the doc or somewhere.