Skip to content

Commit

Permalink
Update readme with Pow installation
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultzer committed Sep 5, 2018
1 parent b6d9649 commit eb171c7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Run `mix deps.get` to install it.

## Getting started

### Pow

It's required to set up [Pow](https://github.com/danschultzer/pow#getting-started-phoenix) first. You can [run these quick setup](guides/POW.md) instructions if Pow hasn't already been set up.

### PowAssent

Install the necessary files:

```bash
Expand All @@ -58,7 +64,7 @@ PRIV_PATH/repo/migrations/TIMESTAMP_create_user_identities.ex
Update `LIB_PATH/users/user.ex`:

```elixir
defmodule MyApp.Users.User
defmodule MyApp.Users.User do
use Ecto.Schema
use Pow.Ecto.Schema
use PowAssent.Ecto.Schema
Expand Down Expand Up @@ -123,7 +129,7 @@ Otherwise, Pow will raise an error about missing template when the user id field

### Provider links

You can use `PowAssent.Phoenix.ViewHelpers.provider_links/1` to add provider links to your `registration` and `session` template files:
You can use `PowAssent.Phoenix.ViewHelpers.provider_links/1` to add provider links to your template files:

```elixir
<h1>Registration</h1>
Expand Down Expand Up @@ -152,7 +158,7 @@ config :my_app, :pow_assent,
]
```

Now start (or restart) your Phoenix app, and visit `http://localhost:4000/registrations/new`. You'll see a "Sign in with Github" link if you have added the `PowAssent.Phoenix.ViewHelpers.provider_links/1` to your template.
Now start (or restart) your Phoenix app, and visit `http://localhost:4000/auth/github/new`.

## Custom provider

Expand Down
66 changes: 66 additions & 0 deletions guides/POW.md
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.

0 comments on commit eb171c7

Please sign in to comment.