Bouncer.Session

A library of functions used to work with session data.

Summary

Functions

Retrieves the specified session store adapter from the application config

Retrieves session data given an authorization token and assigns it to the connection

Assigns the user session data to the connection

Creates a session for a given user and saves it to the session store. Returns the session token which will be used as the API authorization token

Destroys a session by removing session data from the store

Verifies that the ID deciphered from the received token matches the ID in the session data

Convenience function to determine if the ID from the current_user in the request matches the given User ID

Functions

adapter()

Retrieves the specified session store adapter from the application config.

assign_current_user(conn)

Retrieves session data given an authorization token and assigns it to the connection.

assign_current_user(user, conn)

Assigns the user session data to the connection.

create(conn, user)

Creates a session for a given user and saves it to the session store. Returns the session token which will be used as the API authorization token.

destroy(key)

Destroys a session by removing session data from the store.

user_matches?(response, conn)

Verifies that the ID deciphered from the received token matches the ID in the session data.

user_request?(conn, id)

Convenience function to determine if the ID from the current_user in the request matches the given User ID.

examples

iex> Bouncer.Session.user_request? %{assigns: %{current_user: %{id: 1}}},
...> 1
true
iex> Bouncer.Session.user_request? %{assigns: %{current_user: %{id: 1}}},
...> "1"
true
iex> Bouncer.Session.user_request? %{assigns: %{current_user: %{id: 1}}},
...> "2"
false
iex> Bouncer.Session.user_request? %{assigns: %{}}, 1
false