Phauxth v0.15.0 Phauxth.Authenticate View Source
Authenticate the current user, using Plug sessions or api tokens.
Options
There are three options:
method - the method used to authenticate the user
- this is either
:session
(using sessions) or:token
(using api tokens) - the default is
:session
- this is either
max_age - the length of the validity of the token
- the default is one day
user_context - the user context module to be used
- the default is MyApp.Accounts
Examples
Add the following line to the pipeline you want to authenticate in
the web/router.ex
file:
plug Phauxth.Authenticate
To use with an api, add the token method option:
plug Phauxth.Authenticate, method: :token
Link to this section Summary
Functions
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
Get the user based on the session id or token id.
This function also calls the database to get user information.
Log the result of the authentication and return the user struct or nil.
Set the current_user
variable.