I'm going through the Phoenix Guide on Sessions. It explains it very well how I can bind data to a session using put_session
and fetch the value later using get_session
but it doesn't tell how I can delete a User's session.
From the guide:
defmodule HelloPhoenix.PageController do
use Phoenix.Controller
def index(conn, _params) do
conn = put_session(conn, :message, "new stuff we just set in the session")
message = get_session(conn, :message)
text conn, message
end
end
Found it in the Plug Docs:
clear_session(conn)
Clears the entire session.
This function removes every key from the session, clearing the session.
Note that, even if clear_session/1 is used, the session is still sent to the client. If the session should be effectively dropped, configure_session/2 should be used with the :drop option set to true.
You can put something like this in your SessionsController
:
def delete(conn, _) do
conn
|> clear_session()
|> redirect(to: page_path(conn, :index))
end
and add a route for this in your web/router.ex
.
I think what you're looking for is configure_session:
Plug.Conn.configure_session(conn, drop: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With