Adding authorization with JWT
We now have an application that allows us to log in and return the logged in user. However, if we want to use the login in any API, we'll have to create an authorization mechanism. This mechanism should enable the users of the API to authenticate, get a token, and use that token to identify themselves and access resources.
We're doing this as we want to close part of the application's routes so that they're only available to authenticated users.
We'll develop what's needed to integrate with token authentication by using JSON Web Tokens (JWT), which is pretty much a standard in APIs nowadays.
If you are not familiar with JWT, I'll leave you with an explanation from jwt.io:
It is mainly used when you want your clients to connect to an authentication service, and them provide your...