concept session in category elixir

appears as: session, sessions
Phoenix in Action

This is an excerpt from Manning's book Phoenix in Action.

Next, Plug.Session sets up a session, which will handle your session data, such as cookies, used for serving up dynamic web pages that are customized for each user. Finally, your data is transferred to the BlogWeb.Router plug, which ultimately routes the request to the correct handler within the application (we’ll look at that next).

The good news is that Phoenix has session support built-in—you don’t have to do anything. Beyond that, the data in the session can be encrypted if you want to keep your users’ prying eyes out of the data you store in there. If you open .../auction_web/endpoint.ex, you’ll see all the plugs that the connection is fed through before it hits the router. One of those is Plug.Session, shown in the following listing, and it’s generated by default.

Listing 10.13. The section of endpoint.ex that sets up your session
defmodule AuctionWeb.Endpoint do
  # ...

  # 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.    #1
  plug Plug.Session,
    store: :cookie,
    key: "_auction_web_key",
    signing_salt: "T/6rc89M"                                      #2

  # ...
end

You can also see, in your router module (at .../auction_web/router.ex), that the default browser pipeline runs through a plug named :fetch_session. That plug sets up the session so it can be read from and written to within the Plug.Conn struct that passes from point to point during a request.