0
votes

I'm making a signin controller.

I set the session as such:

conn = put_session(conn, :user_id, user.id)
IEx.pry
redirect conn, to: account_path(conn, :show)

It looks set as on the pry line when I print the conn I get

...
:plug_session => %{"user_id" => 6}, :plug_session_fetch => :done,
...

Then in the next controller which we redirect to we get

get_session(conn, :user_id) => nil

The 302 from the signin controller seems to set a session cookie as the response includes

set-cookie:_rebirth_key=g3QAAAABbQAAAAd1c2VyX2lkYQY=--KJ9iow5QUIqw1ggyPla--EGp-dY=; path=/; HttpOnly

How do I make the session persist?

Thanks!

2

2 Answers

2
votes

I am not sure but I think fetch_session might not be the right function to get the value from the session. Try

get_session(conn, :user_id)

instead.

0
votes

To people who might run into the same problem I did; make sure you're not calling configure_session(drop: true) unless you really want to.

If, in an attempt to enforce a fresh session (like if a user just logged in) and you call conn |> configure_session(drop: true) |> clear_session |> put_session(:key, value), your session will be empty.