Chapter 8. Server-rendered views

 

This chapter covers

  • Introducing server-rendered views
  • Using server-rendered views in an authentication scheme
  • Setting up the layout page and using partials
  • Using locals to make backend data accessible to views
  • Bootstrapping data directly into views with EJS tags

It’s now a well-known fact that we’re building the greatest virtual edifice to cat videos on the planet Earth, better known as Brushfire. In chapter 6, we embarked on the design and implementation of an identity, authentication, personalization, and access control system, and we established identity with a user model. In chapter 7, we connected that model to frontend elements that enabled a user to create a user record and manage it. Now that a user can create an identity, our next step is deciding how that identity will affect the frontend assets available to the user once they’ve proven they are who they say they are—a process known as authentication.

Definition

When we use the terms authentication or authenticated state, we’re referring to whether a user’s claim, on behalf of a user-agent, is genuine. This is typically referred to as a user being logged in or logged out of an application.

For example, as figure 8.1 shows, if a user is authenticated, we’ll display the user’s Gravatar image and email address in the navigation bar. If the user is not authenticated, we want to display the login form instead.

8.1. Page navigation

8.2. Personalizing web pages

8.3. Transitioning from an SPA

8.4. Summary