Chapter 5. React Blog App Part 2 – Users

This chapter covers user session management as well as creating, viewing, and listing users (bloggers).

Our primary focus for the app is posts, but a post must be associated with a user identity. User account management is an often-underestimated and complex part of applications. One of the more difficult aspects of account management is security. Since we are making a mock application, we won't have much security. We are going to establish the user identity with a simple comparison during log in. If we moved beyond this prototype into a real, deployable, application, we'd replace most of this session management code with software that's suited specifically for user identity management.

This chapter comprises all of the code needed to get our user management in order. Since the application is already scaffolded, the code breakdown benefits from being organized by entity type (configurations, stores, and views). By the end of this chapter we'll be able to sign up, log in, log out, list, and view user accounts. The application throughout this chapter can be found in the ch7.zip code bundle.

The construction of the application is done in four parts:

  • Part 1: Actions and common components
  • Part 2: User account management
  • Part 3: Blog post operations
  • Part 4: Infinite scroll and search

Code manifest

Below is a manifest for all of the code in this chapter. You can follow along with code listings in the ch7.zip code bundle included with this book.

The user and session context stores are the first time the API endpoint will appear. The API URL root resides in the application configuration module:

  • Application configuration: js/appConfig.js

Getting user accounts fully up-and-running will introduce these dependencies. One is for managing cookies' client-side. The other is for form validation. Here are those dependencies:

  • Cookie reader/writer: js/vendor/cookie.js
  • Form utilities mixin: js/mixins/utility.js

For our application, we are mocking user account management. So, there's a separate store for managing the session and another store for the user data:

  • Session context store: js/stores/sessionContext.js
  • Users store: js/stores/users.js

User-related views, and their respective styles, include:

  • Login view: js/views/login.jsx
  • User edit view: js/views/users/edit.jsx, css/views/user/edit.less
  • User view component: js/components/users/view.jsx, css/components/users/view.less
  • User list view: js/views/users/list.jsx, css/views/user/list.less
  • User view: js/views/users/view.jsx, css/views/user/view.less

Another affected view, which we have already defined and will need to update, is the application header:

  • Application header: js/views/appHeader.jsx (add session awareness, welcome, logout)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.94.209