raxx_session v0.2.4 Raxx.Session

A session is extracted from a request using extract/2. An updated session is sent the the client using embed/3 or a response To expire a session use expire/2 on a response.

Configuration

All session functions take a configuration as a parameter. To check configuration only one it is best to configure a session, and it's store, at startup.

When using the SignedCookie or EncryptedCookie store then sessions are compatible with sessions from plug applications.

Options

  • :store - session store module (required)
  • :key - session cookie key (required)

Any option that can be passed as an option to SetCookie.serialize/3 can be set as a session option. :domain, :max_age, :path, :http_only, :secure, :extra

Store options

Additional options may be required dependant on the store module being used. For example SignedCookie requires secret_key_base and salt.

Link to this section Summary

Functions

Extract and discard all flash messages in a users session.

Set up and check session configuration.

Overwrite a users session to a new value.

Instruct a client to end a session.

Extract a session from a request.

Returns all the flash messages in a users session.

Add a message into a sessions flash.

Link to this section Functions

Link to this function

clear_flash(session)

Extract and discard all flash messages in a users session.

Link to this function

config(options)

Set up and check session configuration.

See options for details.

Link to this function

embed(response, session, config)

Overwrite a users session to a new value.

The whole session object must be passed to this function.

Link to this function

expire(response, config)

Instruct a client to end a session.

Link to this function

extract(request, config)

Extract a session from a request.

Returns {:ok, nil} if session cookie is not set. When session cookie is set but cannot be decoded or is tampered with an error will be returned.

Link to this function

extract(request, user_token, config)

Link to this function

get_csrf_token(session)

See Raxx.Session.CSRFProtection.get_csrf_token/1.

Link to this function

pop_flash(session)

Returns all the flash messages in a users session.

This will be a map of %{key => message} set using put_flash/3. The returned session will have no flash messages. Remember this session must be embedded in the response otherwise flashes will be seen twice.

Link to this function

put_flash(session, key, message)

Add a message into a sessions flash.

Any key can be used for the message, however :info and :error are common.