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)
Cookie options
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
clear_flash(session)
Extract and discard all flash messages in a users session.
config(options)
Set up and check session configuration.
See options for details.
embed(response, session, config)
Overwrite a users session to a new value.
The whole session object must be passed to this function.
expire(response, config)
Instruct a client to end a session.
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.
extract(request, user_token, config)
get_csrf_token(session)
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.
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.