-
Notifications
You must be signed in to change notification settings - Fork 21
Home
Welcome to the Phauxth wiki!
Phauxth is an authentication library for Phoenix applications.
Phauxth offers two types of functions: Plugs, which are called with
plug
, and verify/2
functions, which are called inside the function
bodies.
Plugs take a conn
and opts
as arguments and return a conn
.
Phauxth.Authenticate checks to see if there is a valid cookie or token for the user and sets the current_user value accordingly.
This is usually added to the pipeline you want to authenticate in
the router.ex
file, as in the following example.
pipeline :browser do
plug Phauxth.Authenticate
end
This Plug provides a check for a remember_me
cookie.
pipeline :browser do
plug Phauxth.Authenticate
plug Phauxth.Remember
end
This needs to be called after plug Phauxth.Authenticate
Each verify/2
function takes a map (usually Phoenix params) and opts
(an empty list by default) and returns {:ok, user} or {:error, message}.
In the example below, Phauxth.Login.verify is called within the create
function in the session controller.
def create(conn, %{"session" => params}) do
case Phauxth.Login.verify(params) do
{:ok, user} -> handle_successful_login
{:error, message} -> handle_error
end
end
Phauxth.Otp.verify is used for logging in with one-time passwords, which are often used with two-factor authentication.
Phauxth.Confirm.verify is used for user confirmation, using email or phone.
Phauxth.Confirm.PassReset.verify is used for password resetting.
To get started, go to the New project page.