View Source AshAuthentication.Phoenix.Router (ash_authentication_phoenix v1.0.1)
Phoenix route generation for AshAuthentication.
Using this module imports the macros in this module and the plug functions
from AshAuthentication.Phoenix.Plug
.
usage
Usage
Adding authentication to your live-view router is very simple:
defmodule MyAppWeb.Router do
use MyAppWeb, :router
use AshAuthentication.Phoenix.Router
pipeline :browser do
# ...
plug(:load_from_session)
end
pipeline :api do
# ...
plug(:load_from_bearer)
end
scope "/", MyAppWeb do
pipe_through :browser
sign_in_route
sign_out_route AuthController
auth_routes_for MyApp.Accounts.User, to: AuthController
end
Link to this section Summary
Types
Options that can be passed to auth_routes_for
.
A sub-path if required. Defaults to /auth
.
Any options which should be passed to the generated scope.
The controller which will handle success and failure.
Functions
Generates the routes needed for the various strategies for a given AshAuthentication resource.
Generates a generic, white-label sign-in page using LiveView and the
components in AshAuthentication.Phoenix.Components
.
Generates a sign-out route which points to the sign_out
action in your auth
controller.
Link to this section Types
@type auth_route_options() :: [path_option() | to_option() | scope_opts_option()]
Options that can be passed to auth_routes_for
.
@type path_option() :: {:path, String.t()}
A sub-path if required. Defaults to /auth
.
@type scope_opts_option() :: {:scope_opts, keyword()}
Any options which should be passed to the generated scope.
@type to_option() :: {:to, AshAuthentication.Phoenix.Controller.t()}
The controller which will handle success and failure.
Link to this section Functions
@spec auth_routes_for(Ash.Resource.t(), auth_route_options()) :: Macro.t()
Generates the routes needed for the various strategies for a given AshAuthentication resource.
This is required if you wish to use authentication.
options
Options
to
- a module which implements theAshAuthentication.Phoenix.Controller
behaviour. This is required.path
- a string (starting with "/") wherein to mount the generated routes.scope_opts
- any options to pass to the generated scope.
example
Example
scope "/", DevWeb do
auth_routes_for(MyApp.Accounts.User,
to: AuthController,
path: "/authentication",
scope_opts: [host: "auth.example.com"]
)
end
sign_in_route(path \\ "/sign-in", live_view \\ AshAuthentication.Phoenix.SignInLive, opts \\ [])
View Source (macro)Generates a generic, white-label sign-in page using LiveView and the
components in AshAuthentication.Phoenix.Components
.
This is completely optional.
sign_out_route(auth_controller, path \\ "/sign-out", opts \\ [])
View Source (macro)Generates a sign-out route which points to the sign_out
action in your auth
controller.
This is optional, but you probably want it.