Chapter 10. Plugs, assigns, and dealing with session data

 

This chapter covers

  • Creating modules that implement the Plug behavior
  • Passing information through your application in assigns
  • Handling user authentication

In the past couple of chapters, you’ve created routes and controllers needed for creating, viewing, and editing items for your auction web application. That’s been great, but there’s a glaring hole: bids. How can you have an auction without bids? Furthermore, how can you track who a bid is from if you don’t have users?

Before you expand the number of structs in your application by adding bids (which you’ll do in the next chapter), we’ll discuss creating users in your application. The main focus of this chapter is using session data in your application. Session data will allow you to know when a user is logged in and what pages they’re visiting.

Figure 10.1 illustrates this concept. Each user of your auction site carries session data in their browser that lets you know who they are. Phoenix will use that session data to build a custom response for them as they navigate the site.

Figure 10.1. A user’s session data will help Phoenix build a web page specific to them.

These custom responses could be as simple as displaying their name in a welcome message, or as complex as restricting access to certain parts of the auction site based on their permission level.

10.1. Preparing your application for user registration

10.2. Handling user login and sessions

10.3. Plugs

10.4. Adding site navigation

10.5. Restricting users from certain pages

Summary