In liveview
, how can I pass the user data from leex
to the context
?
I have phx.gen.live
a profiles
context, and I want to add user_id to the profile every time user create the new profile.
I change the create_profile code to:
**profiles.ex (context)**
def create_profile(attrs \\ %{}, userid) do
attrs = Map.put(attrs, "user_id", userid)
%Profile{}
|> Profile.changeset(attrs)
|> Repo.insert()
end
I am using pow
, so in normal phoenix case, I would just do this:
user = Pow.Plug.current_user(conn) #<-- this is conn
Profiles.create_profile(profile_params, user.id)
but in liveview
, instead of conn
, it use socket
. So I am not sure how to go about it.