pow-auth / pow_site

Website for Pow
https://powauth.com
MIT License
4 stars 2 forks source link

Snippet: use custom route paths, disable routes #16

Closed joepstender closed 4 years ago

joepstender commented 4 years ago

How to use custom route paths

From: https://github.com/danschultzer/pow/issues/248#issuecomment-521225322

They can be overridden, the same way you would override routes normally in Phoenix:

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

  # ...

  scope "/", Pow.Phoenix, as: "pow" do
    get "/sign_up", RegistrationController, :new
    post "/sign_up", RegistrationController, :create
    get "/sign_in", SessionController, :new
    post "/sign_in", SessionController, :create
  end

  scope "/" do
    pow_routes()
  end

  # ...
end

How to remove a route

From: https://github.com/danschultzer/pow/issues/254#issuecomment-523232259

You can use the disable registration guide and only enable some routes:

  scope "/" do
    pipe_through :browser

    pow_session_routes()
  end

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

    resources "/registration", RegistrationController, singleton: true, only: [:new, :create, :delete]
  end

The other way is to simply override it:

  scope "/", MyAppWeb do
    pipe_through [:browser]

    resources "/registration", RegistrationController, singleton: true, only: [:edit, :update]
  end

  scope "/" do
    pipe_through :browser

    pow_routes()
  end

That resources definition will catch any requests for /registration/edit and /registration/update, before it gets to the definitions in pow_routes/0.

joepstender commented 4 years ago

This is added to the router documentation. https://github.com/danschultzer/pow/commit/611328fa5e5693466bbdfb4695aab93023ffd4c4

danschultzer commented 4 years ago

:+1: