The React login form

We need to handle the different authentication states of our application:

  • The first scenario is that the user is not logged in and cannot see any posts or chats. In this case, we need to show a login form to allow the user to authenticate themselves.
  • The second scenario is that an email and password are sent through the login form. The response needs to be interpreted, and if the result is correct, we need to save the JWT inside the localStorage of the browser for now.
  • When changing the localStorage, we also need to rerender our React application to show the logged-in state.
  • Furthermore, the user should be able to log out again.
  • We must also handle if the JWT expires and the user is unable to access any functionalities. ...

Get Hands-On Full-Stack Web Development with GraphQL and React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.