This post is going to be about creating an authentication with JSON Web Tokens for your project, presumably an API that’s going to be used by Angular, Vue.js or similar frontend frameworks. We’re going to send the jwt with every request, meaning that we don’t rely on sessions, but simply put the token on every request we make to the API. This way you don’t have to worry about cookies, but you can save it in localStorage
or other places on the frontend.
In essence this tutorial will go through:
- creating a
/login
route to acquire a token - creating a
/secret
route, that only is available to logged in users with a JSON web token
If you’re curious about the final result and don’t want the step by step guide, check out the final jwt express gist.
Continue reading “Express, Passport and JSON Web Token (jwt) Authentication for Beginners”