Displaying the logged in user

In this user story, we will display the username of the logged in user on the screen. To implement this user story, we will take the following steps:

  • Add a method to the authenticator module to extract and return the username from the JWT
  • Update the view to display the logged in user in the navigation bar

Let's start by adding a method to the authenticator module. We will name this method loggedInUser and make it a pure observable so that it can be used in the view. We will extract the username form the JWT we received from the server. Recall the JWT structure described earlier in this chapter. The JWT is base64 encoded with dot (.) as the separator between head, body, and signature. To retrieve the username, we will ...

Get KnockoutJS by Example 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.