Phauxth v1.2.8 Phauxth.Remember View Source

Remember me module.

Calling Phauxth.Remember with plug checks for a remember_me cookie, which contains a token. The token is then checked, and if it is valid, the user is added to the session.

This module also contains functions to add / delete the remember_me cookie.

Options

There are three options:

  • :max_age - the length of the validity of the cookie / token

    • the default is one week
  • :user_context - the user context module to be used

    • the default is given by Phauxth.Config.user_context()
  • :log_meta - additional custom metadata for Phauxth.Log

    • this should be a keyword list

In addition, there are also options for generating the token. See the documentation for the Phauxth.Token module for details.

Examples

Add the following line to the pipeline you want to authenticate in the web/router.ex file:

plug Phauxth.Authenticate
plug Phauxth.Remember

Make sure you add the Phauxth.Remember Plug after Phauxth.Authenticate.

Link to this section Summary

Functions

Check the session for the current user

Check the token for the current user

Delete the remember_me cookie from the conn

Checks to see if the session is fresh - newly logged in

Get the user based on the session id or token id

Log the result of the authentication and return the user struct or nil

Set the current_user variable

Link to this section Functions

Link to this function add_rem_cookie(conn, user_id, max_age \\ 604800, extra \\ "") View Source

Add a remember me cookie to the conn.

Check the session for the current user.

Link to this function check_token(conn, token, max_age, opts) View Source

Check the token for the current user.

Delete the remember_me cookie from the conn.

Checks to see if the session is fresh - newly logged in.

Get the user based on the session id or token id.

This function also calls the database to get user information.

Link to this function get_user(conn, token, arg) View Source

Log the result of the authentication and return the user struct or nil.

Set the current_user variable.