# Session - values not set?

**URL:** <https://forum.elixirforum.com/t/session-values-not-set/40143>\
**Category:** Questions\
**Tags:** phoenix, session\
**Created:** [May 31, 2021, 6:43pm UTC](https://forum.elixirforum.com/t/session-values-not-set/40143 "2021-05-31T18:43:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![silverdr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/silverdr/32/23771_2.png) [@silverdr](https://forum.elixirforum.com/u/silverdr)\
**Post date:** [May 31, 2021, 6:43pm UTC](https://forum.elixirforum.com/t/session-values-not-set/40143/1 "2021-05-31T18:43:10Z")

</div>

I might be doing something completely wrong here, but…

```elixir
def create(conn, params) do
	put_session(conn, :gin, "tonic")
	Logger.debug "SESSION: #{inspect(get_session(conn))}"
	[...]
end

```

shouldn’t this controller action set the value for given key in the session?

What I get is only:

`[debug] SESSION: %{"_csrf_token" => "cVSOEuWk1iGWN-iIfskUyNF6"}`

And if I check for the exact key I used in `put_session()` I get `nil`. Any clues what I am doing wrong?

Configuration is the default one with `endpoint.ex` reading:

```elixir
  # The session will be stored in the cookie and signed,
  # this means its contents can be read but not tampered with.
  # Set :encryption_salt if you would also like to encrypt it.
  @session_options [
    store: :cookie,
    key: "_<the_app_name>_key",
    signing_salt: "ELJOxI/O"
  ]

```

where `<the_app_name>` is of course the correct application name

---

<div class="post-metadata">

**Author:** ![stefanchrobot](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stefanchrobot/32/7657_2.png) [@stefanchrobot](https://forum.elixirforum.com/u/stefanchrobot)\
**Post date:** [May 31, 2021, 8:44pm UTC](https://forum.elixirforum.com/t/session-values-not-set/40143/2 "2021-05-31T20:44:15Z")

</div>

Elixir data structures are immutable. You need to capture the result of `put_session`:

```elixir
def create(conn, params) do
  conn = put_session(conn, :gin, "tonic")
  Logger.debug "SESSION: #{inspect(get_session(conn))}"
  # ...
end

```

---

<div class="post-metadata">

**Author:** ![silverdr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/silverdr/32/23771_2.png) [@silverdr](https://forum.elixirforum.com/u/silverdr)\
**Post date:** [May 31, 2021, 9:02pm UTC](https://forum.elixirforum.com/t/session-values-not-set/40143/3 "2021-05-31T21:02:15Z")

</div>

Gosh! Yes, absolutely! But that was actually only a debug error. My actual problem was something else - an “unsafe” variable (if I understand correctly the term): `conn` was assigned _inside_ an `unless` block rather than being returned from it to an assignment. Yeah… Elixir _is_ different than everything I used before 😉 @stefanchrobot thanks for pointing me in the right direction! Even if indirectly 🙂
