Learn how to implement Authentication in your Node project using JsonWebTokens, BCrypt and HTTP Cookies.

So, you’ve decided to finally broach the topic of authentication within your Node application. Come to find out there are of course a ton of ways to implement Auth within Node, so where do you start? First choice is to decide whether you want to just let a third party service handle it for you, or whether you’re brave enough to carry through and implement it on your own! If the second choice is for you, well then you’ve come to right place. I’m going to walk you through one (of many) methods you can use to implement Auth in your Node project using JsonWebTokens, BCrypt and HTTP Cookies.

First things first, why use JsonWebTokens, BCrypt, and Cookies?

Great question, starting with what are JWT’s and why use them? To quote from their documentation: “A JSON Web Token (JWT) is an open standard (RFC 7519_) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object.” _If you’re creating a Node application you’re more than likely very familiar with JSON. So essentially a JWT exactly what the name implies, a compact token used to transmit data between parties, written in JSON. Implementation of using JWTs within a Node App is quite easy as well. A simple:

npm install --save jsonwebtoken

will include it as a dependency and we can therefore call on the module when needed through the application.

Next we have BCrypt, the most straightforward to explain, is simply a middleware for hashing passwords. There are of course many others but BCrypt is widely used, easy to install and has great documentation, which is everything you need to get started so let’s include that into the project as well:

npm install --save bcryptjs

#jwt #programming #nodejs #javascript #node

Authentication in Node.js, with HTTP Cookies, JWT & BCrypt
4.55 GEEK