Hello Guys
I am trying to add some info in the session but inspecting my conn struct does not show the values have been added(they are not in the conn struct). Below is part of the code doing that
def create_session(conn, %{"jwt" => jwt, "user_type" => user_type}) do
case App.Auth.authenticate(jwt) do
%Session{} = session ->
conn
|> put_session(:token, jwt)
|> put_session(:user_id, session.user_id)
......some other code
end
end
confirming if the token is set in the session with jwt = conn.private.plug_session[:token]
returns nil.
What might I be missing? Thanks in advance
Maybe
conn = conn
|> ...
but it’s not clear without the rest of the code
here is the rest of the code.
def create_session(conn, %{"jwt" => jwt, "user_type" => user_type}) do
case Ponos.Auth.authenticate(jwt) do
%Session{} = session ->
conn
|> put_session(:token, jwt)
|> put_session(:user_id, session.user_id)
case user_type do
"customer" ->
customer = CustomerServer.get(session.user_id)
if customer.name == nil do
conn
|> put_flash(:info, "Success")
|> redirect(to: Routes.user_path(conn, :set_user, session: session.user_id, user_type: user_type))
else
if length(customer.location_ids) <= 0 do
conn
|> put_flash(:info, "Success")
|> redirect(to: Routes.location_apath(conn, :location, session: session.user_id, user_type: user_type))
end
end
_ ->
IO.puts("not a customer")
end
{:error, :signature_error} ->
conn
|> put_flash(:error, "Error while authenticating")
|> redirect(to: "/")
end
end
Yeah its true. This solved it.
Thank you @kokolegorille