View Source Pow.Phoenix.Router (Pow v1.0.38)

Handles Phoenix routing for Pow.

Resources are build with pow_resources/3 and individual routes are build with pow_route/5. The Pow routes will be filtered if a route has already been defined with the same action, router helper alias, and number of bindings. This makes it easy to override pow routes with no conflicts.

The scope will be validated to ensure that there is no aliases. An exception will be raised if an alias was defined in any scope around the pow routes.

Usage

Configure lib/my_project_web/router.ex the following way:

defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  use Pow.Phoenix.Router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  scope "/" do
    pipe_through :browser

    pow_routes()
  end

  # ...
end

Disable registration routes

pow_routes/0 will call pow_session_routes/0 and pow_registration_routes/0. Registration of new accounts can be disabled just by calling pow_session_routes/0 instead of pow_routes/0:

defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  use Pow.Phoenix.Router

  # ...

  # Uncomment to permit update and deletion of user accounts:
  # scope "/", Pow.Phoenix, as: "pow" do
  #   pipe_through :browser
  #
  #   resources "/registration", RegistrationController, singleton: true, only: [:edit, :update, :delete]
  # end

  scope "/" do
    pipe_through :browser

    pow_session_routes()
  end

  # ...
end

Customize Pow routes

Pow routes can be overridden by defining them before the pow_routes/0 call. As an example, this can be used to change path:

defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  use Pow.Phoenix.Router

  # ...

  scope "/", Pow.Phoenix, as: "pow" do
    pipe_through :browser

    get "/sign_up", RegistrationController, :new
    post "/sign_up", RegistrationController, :create

    get "/login", SessionController, :new
    post "/login", SessionController, :create
  end

  scope "/" do
    pipe_through :browser

    pow_routes()
  end

  # ...
end

Summary

Functions

See Phoenix.Router.Route.exprs/2.

Link to this macro

pow_route(verb, path, plug, plug_opts, options \\ [])

View Source (macro)

Pow routes macro.

Use this macro to define the Pow routes. This will call pow_session_routes/0 and pow_registration_routes/0.

Example

scope "/" do
  pow_routes()
end
@spec validate_scope!(atom() | [Phoenix.Router.Scope.t()]) :: :ok