Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

put_flash not works with configure_session(drop: true)

In my phoenix project I have the following action in controller which is responsible for signing out user:

  def signout(conn, _params) do
    conn
    |> configure_session(drop: true)
    |> put_flash(:info, "Signed out successfully!")
    |> redirect(to: project_path(conn, :index))
  end

The problem is that when I use configure_session(drop: true)flash message is not appearing on the screen. How can I fix that?

like image 600
Mateusz Urbański Avatar asked Mar 20 '17 17:03

Mateusz Urbański


1 Answers

Use clear_session/1 instead of configure_session/2. Using :drop on configure_session/2 will completely remove the session cookie and no cookie will be sent with the response.

clear_session/1 will remove all keys from the session, but keep the session cookie sent to the client. So you can still add your put_flash into the session cookie after you have cleared it.

like image 142
cpjolicoeur Avatar answered Oct 14 '22 03:10

cpjolicoeur