durlav kalita

Hi, I am Durlav. Developer and chess enthusiast.

Home Blog Projects About View on GitHub
    18 August 2021

    Auth using jwt

    by durlavk

    Authorization is perhaps the most important and difficult part of any web app. Different framework handle authorization differently. Unlike some other framework where authorization scaffolding is provided, in nodejs authorization has to be done manually and that’s where jwt comes in.

    jwt stands for jason web token. As the name suggests implementing jwt in node app provides a token for individual user which can be used to verify them and provide access to specific routes. To use jwt in node app we have to first install jsonwebtoken npm module by npm i jsonwebtoken. We can import jsonwebtoken by running const jwt = require('jsonwebtoken');. Now jwt has two main part sign and verify. We have to first sign the user data to get a token and then we can use verify later to check whether if the token is correct or not.

    This is just a brief implementation of jwt that I seem to understand easily and there are other ways to implement it as well. Also jwt and passportjs can used together to make more robust auth system.

    Check out the following links for more info- jwt github jwt implementation video

    tags: auth - jwt - nodejs