bouncer v0.3.0 Bouncer.Session

A library of functions used to work with session data.

Summary

Functions

Destroys a session given a token and a user ID

Destroys all sessions associated with a given user ID

Generates a session token. The ttl (time-to-live) defaults to 2 weeks. See Bouncer.Token.Generate/4

Retrieves session data given an authorization token and puts it into the connection

Puts the user session data into the connection

Saves session data given a key and optional ttl (time-to-live)

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

Verifies a session token is valid and matches the given user. See Bouncer.Token.Verify/4

Functions

adapter()
destroy(token, id)

Destroys a session given a token and a user ID.

destroy_all(conn, id)

Destroys all sessions associated with a given user ID.

generate(conn, user, ttl \\ 1210000)

Generates a session token. The ttl (time-to-live) defaults to 2 weeks. See Bouncer.Token.Generate/4.

put_current_user(conn)

Retrieves session data given an authorization token and puts it into the connection.

put_current_user(arg, conn)

Puts the user session data into the connection.

save(data, key, ttl)

Saves session data given a key and optional ttl (time-to-live).

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? %{private: %{current_user: %{"id" => 1}}},
...> 1
true
iex> Bouncer.Session.user_request? %{private: %{current_user: %{"id" => 1}}},
...> "1"
true
iex> Bouncer.Session.user_request? %{private: %{current_user: %{"id" => 1}}},
...> "2"
false
iex> Bouncer.Session.user_request? %{private: %{}}, 1
false
verify(conn, token)

Verifies a session token is valid and matches the given user. See Bouncer.Token.Verify/4.