Phauxth.Login.Base (Phauxth v2.5.1) View Source

Base module for handling login.

This is used by Phauxth.Login and can also be used to create custom login modules.

Custom login modules

One example of a custom login module is shown below:

defmodule MyApp.LoginConfirm do
  use Phauxth.Login.Base

  @impl true
  def authenticate(%{"password" => password} = params, user_context, opts) do
    case user_context.get_by(params) do
      nil -> {:error, "no user found"}
      %{confirmed_at: nil} -> {:error, "account unconfirmed"}
      user -> Phauxth.Login.check_pass(user, password, opts)
    end
  end
end

In this example, the authenticate function is overridden to check the user struct to see if the user is confirmed. If the user has not been confirmed, an error is returned.