Skip to content

Commit 72573aa

Browse files
committed
Mention phx.gen.auth
1 parent 11002c7 commit 72573aa

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,27 @@ This is all. Run `mix phx.server` and access the "/dashboard" to configure the n
9898

9999
### Extra: Add dashboard access on all environments (including production)
100100

101-
If you want to use the LiveDashboard in production, you should put it behind some authentication and allow only admins to access it. If your application does not have an admins-only section yet, you can use `Plug.BasicAuth` to set up some basic authentication as long as you are also using SSL (which you should anyway):
101+
If you want to use the LiveDashboard in production, you should put authentication in front of it. For example, if you use `mix phx.gen.auth` to generate an Admin resource, you could use the following code:
102+
103+
```elixir
104+
# lib/my_app_web/router.ex
105+
use MyAppWeb, :router
106+
import Phoenix.LiveDashboard.Router
107+
108+
...
109+
110+
pipeline :admins_only do
111+
plug :fetch_current_admin
112+
plug :require_authenticated_admin
113+
end
114+
115+
scope "/" do
116+
pipe_through [:browser, :admins_only]
117+
live_dashboard "/dashboard"
118+
end
119+
```
120+
121+
If you'd rather have some quick and dirty HTTP Authentication, the following code can be used as a starting point:
102122

103123
```elixir
104124
# lib/my_app_web/router.ex
@@ -125,12 +145,6 @@ end
125145

126146
If you are running your application behind a proxy or a webserver, you also have to make sure they are configured for allowing WebSocket upgrades. For example, [here is an article](https://web.archive.org/web/20171104012240/https://dennisreimann.de/articles/phoenix-nginx-config.html) on how to configure Nginx with Phoenix and WebSockets.
127147

128-
Finally, you will also want to configure your `config/prod.exs` and use your domain name under the `check_origin` configuration:
129-
130-
check_origin: ["//myapp.com"]
131-
132-
Then you should be good to go!
133-
134148
## Using from the command line with PLDS
135149

136150
It's possible to use the LiveDashboard without having to add it as a dependency of your

0 commit comments

Comments
 (0)