Scaffold the Admin Dashboard
Explore how to scaffold an admin dashboard in Phoenix by defining routes, setting layouts, creating controllers, and establishing socket connections with basic authentication. Understand how to separate admin assets and configure websocket channels, laying the foundation for real-time shopping cart tracking using Phoenix Presence.
We'll cover the following...
The admin dashboard
There are many moving parts in setting up a brand new section of an application. We’ll tackle this together to see how we’d go about it in other projects. Our scaffolding will consist of these steps:
- Define our new
Routerentries. - Set up an admin layout.
- Create the
Admin.DashboardController. - Create the
Admin.SocketandAdmin.DashboardChannel. - Create admin JS and CSS.
We’ll move quickly through these steps. Once this is done, we’ll have the proper foundation to build our admin dashboard.
We’ll start with our route definition. Our admin dashboard will be behind an HTTP Basic Auth screen, and luckily there is a library to help with this. Let’s add the basic_auth library to our mix file.
Let’s run mix deps.get after we add it. Next, we’ll configure our local login to be “admin/password.” Let’s add this snippet to the end of our dev config file:
We will enter these credentials when the HTTP Basic Auth screen appears. Now we are ready ...