AshAuthentication.Phoenix

The ash_authentication_phoenix package extends ash_authentication by adding router helpers, plugs and behaviours that makes adding authentication to an existing Ash-based Phoenix application dead easy.

Warning

This is beta software. Please don't use it without talking to us!

Installation

The package can be installed by adding ash_authentication_phoenix to your list of dependencies in mix.exs:

def deps do
[
{:ash_authentication_phoenix, "~> 1.0.1"}
]
end

If you wish to use our default Tailwind-based components, you will need to add the path to ash_authentication_phoenix's components in your assets/tailwind.config.js:

module.exports = {
content: [
// Other paths.
"../deps/ash_authentication_phoenix/**/*.ex"
]
}

Usage

This package assumes that you have Phoenix, Ash and AshAuthentication installed and configured. See their individual documentation for details.

This package is designed so that you can choose the level of customisation required. At the easiest level of configuration, you can just add the routes into your router:

defmodule MyAppWeb.Router do
use MyAppWeb, :router
use AshAuthentication.Phoenix.Router
pipeline :browser do
# ...
plug(:load_from_session)
end
scope "/" do
pipe_through :browser
sign_in_route
sign_out_route MyAppWeb.AuthController
auth_routes_for MyApp.Accounts.User, to: MyAppWeb.AuthController
end
end

This will give you a generic sign-in/registration page and store the authenticated user in the Phoenix session.

Customisation

There are several methods of customisation available depending on the level of control you would like:

  1. Use the generic sign-in liveview.
  2. Apply overrides to set your own CSS classes for all components.
  3. Build your own sign-in pages using the pre-defined components.
  4. Build your own sign-in pages using the generated auth routes.

Documentation

Documentation for the latest release will be available on hexdocs and for the main branch.

Contributing

Licence

MIT