You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-7Lines changed: 21 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,27 @@ This is all. Run `mix phx.server` and access the "/dashboard" to configure the n
98
98
99
99
### Extra: Add dashboard access on all environments (including production)
100
100
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
+
useMyAppWeb, :router
106
+
importPhoenix.LiveDashboard.Router
107
+
108
+
...
109
+
110
+
pipeline :admins_onlydo
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:
102
122
103
123
```elixir
104
124
# lib/my_app_web/router.ex
@@ -125,12 +145,6 @@ end
125
145
126
146
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.
127
147
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
-
134
148
## Using from the command line with PLDS
135
149
136
150
It's possible to use the LiveDashboard without having to add it as a dependency of your
0 commit comments