sheldonkreger
sheldonkreger

Reputation: 938

Setting cookies before a redirect in Phoenix Framework Elixir

I am noticing that my cookies are not being set when I perform put_resp_cookie() before a redirect.

conn
|> put_resp_cookie("shop", shop)

if (some_condition) do:
  redirect conn, to: "/foo/bar"

In my controller function for /foo/bar, the cookie is not set. Is there a way to set the cookie?

Upvotes: 1

Views: 2973

Answers (1)

cpjolicoeur
cpjolicoeur

Reputation: 13106

It appears you did not reassign conn. You simply piped conn into put_resp_cookie/2 but didn't capture the value. You probably intended to do something like this instead

conn = conn |> put_resp_cookie("shop", shop)

Upvotes: 3

Related Questions