-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6d9649
commit eb171c7
Showing
2 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Set up Pow | ||
|
||
First install the necessary files: | ||
|
||
```mix | ||
mix pow.install | ||
``` | ||
|
||
Update `config/config.ex` with the following: | ||
|
||
```elixir | ||
config :my_app, :pow, | ||
user: MyApp.Users.User, | ||
repo: MyApp.Repo | ||
``` | ||
|
||
Set up `WEB_PATH/endpoint.ex` to enable session based authentication: | ||
|
||
```elixir | ||
defmodule MyAppWeb.Endpoint do | ||
use Phoenix.Endpoint, otp_app: :my_app | ||
|
||
# ... | ||
|
||
plug Plug.Session, | ||
store: :cookie, | ||
key: "_my_app_key", | ||
signing_salt: "secret" | ||
|
||
plug Pow.Plug.Session, otp_app: :my_app | ||
|
||
# ... | ||
end | ||
``` | ||
|
||
Add Pow routes to `WEB_PATH/router.ex`: | ||
|
||
```elixir | ||
defmodule MyAppWeb.Router do | ||
use MyAppWeb, :router | ||
use Pow.Phoenix.Router | ||
|
||
# ... | ||
|
||
pipeline :protected do | ||
plug Pow.Plug.RequireAuthenticated, | ||
error_handler: Pow.Phoenix.PlugErrorHandler | ||
end | ||
|
||
scope "/" do | ||
pipe_through :browser | ||
|
||
pow_routes() | ||
end | ||
|
||
# ... | ||
|
||
scope "/", MyAppWeb do | ||
pipe_through [:browser, :protected] | ||
|
||
# Protected routes ... | ||
end | ||
end | ||
``` | ||
|
||
Run `mix ecto.setup` and you can now visit `http://localhost:4000/registration/new` to create a new user. |